I have a specific event (voiceStateUpdate) that has to mention sometimes a Voice Channel:
channel.send(`The Channel is:`+"``"+`<#${newMember.channelID}>`+"``");
As one can see, I want that the channel is being mentioned with those `` around them, so the channel in Discord is in this black box. But my actual output looks like this:
The Channel is: <#1234134234134>
So in Discord this Black Box works, but the Channel is displayed not with its name, but with the ID
To get the right result, you simply imitate Discord's conversion of the format <#CHANNELID>.
channel.send(`The Channel is:`+"`"+`${newMember.channel.name}`+"`");
This will get the exact same result, as if one would post as a user the message with Discord's conversion form
Try it this way:
channel.send('`' + `The Channel is: <#${newMember.channelId}>` + '`');
For a single line code block you only need to wrap it in grave accents once.
Edit:
grafpatron's answer is the correct one
Related
I'm trying to have my bot keep track of items that are being spawned by another bot (Mee6).
The following code gives me a None output.
#client.event
async def on_message(message:discord.Message):
if message.author.bot:
print(message.content)
The command the other bot is responding to is:
/spawn-item member={member} item={item} amount={amount}
I would like to retrieve these values.
Any help would be welcome!
Your code doesn't work, because you want to get an interaction, not a message.
Unfortunately, there is no way to get the interaction of another client. At most you can have a MessageInteraction, which gives you the name of the command used.
But in your case you can make it work since MEE6 still accepts the old command format. If you use the prefix of MEE6 instead of the / command, your code should work (with a bit of reworking: you would need to look at the message right before MEE6's response, or look if a message starts with the MEE6's prefix)
There is api method messages.getReplies in Telegram API and the equivalent of the same is
functions.messages.GetRepliesRequest in the Telethon.
But this method is not returning the expected replies/comments to the post. Instead, it returns multiple messages including the replies to the requested message_id and other messages also which are not even the replies to the requested message_id.
for conv in client.iter_messages(channel.id):
if conv.reply_to:
# get parent message this message reply to
original_message = conv.get_reply_message()
try:
#iterate all the replies for the parent message
for reply in client.iter_messages(channel.id,
reply_to=original_message.id):
print('\tReply message -> ', reply.to_dict())
except telethon.errors.rpcerrorlist.MsgIdInvalidError:
print('exception ***************')
Here it returns the replies to the input message.id in the argument reply_to including the messages which are not the replies to the input message.id.
(I checked the response from of the method call(inner for loop) and their reply_to_msg_id differs from what i requested to get the result).
I could not understand the behaviour of these replies getting in the result.
Also Telegram API docs are not good in shape with example and explantion.
What and how messages are considered as reply to the message in the telegram?
How telegram decides upon the messages whether it is a reply or a normal message?
if a message is reply, then to which message this is a reply?
Given a broadcast channel with comments enabled (let's say the channel's username is username), and a post with a discussion started (comments) for the channel post with message ID 1001, the following code will print all comments for post 1001 in channel username:
async for m in client.iter_messages('username', reply_to=1001):
print(m.text)
This is equivalent to clicking on the "# comment(s)" button in Telegram Desktop. Unfortunately I was not able to reproduce what you mention here:
But this method is not returning the expected replies/comments to the post. Instead, it returns multiple messages including the replies to the requested message_id and other messages also which are not even the replies to the requested message_id.
Now, for the other questions:
What and how messages are considered as reply to the message in the telegram?
Let's look at the problem from a different angle: send_message with comment_to.
First, messages.getDiscussionMessage must be used on the source broadcast channel with the source message ID. This will return the corresponding "discussion message" in the linked "discussion megagroup channel".
Now, messages.sendMessage can be used to send a message in the linked discussion megagroup channel to reply to the corresponding discussion message.
As you can see, "comments" are simply "replies to" the corresponding message of the discussion group. Hence the name, reply_to, during iter_messages.
How telegram decides upon the messages whether it is a reply or a normal message?
In a given chat, messages can reply to other previous messages in the same chat (in Telethon, message.reply_to). However, for channel comments, they're also replies in a way (just in a different chat), hence the parameter name. I tried to stick with Telegram's naming convention and solve the confusion by documenting the parameter but that might've been the wrong choice.
if a message is reply, then to which message this is a reply?
This can be found through message.reply_to.
I've been trying for hours a command that react to a message using the ID.
If someone writes !react (the message ID) the bot reacts to the message.
Can someone help me? I have no clue how to do this.
Use a converter to get the discord.Message instance of the message:
#client.command()
async def react(ctx, message: discord.Message):
...
Then use Message.add_reaction to add a reaction to it, which I'm sure you can figure out by yourself.
Keep in mind that in case the message ID is invalid, can't be found, or is not in the same channel as where the command gets called, the converter will fail & throw you an exception. If you pass in the message's URL instead of the ID, Discord will be able to figure out what channel the message was sent in so you can call the command from wherever you want.
You can get a message's URL by selecting Copy Message Link, which might be better for your users as getting the id requires Developer Mode to be on, which most people don't have enabled. The MessageConverter mentioned in the beginning can parse both id's and URL's so you don't have to worry about that part.
I would like my bot to send a msg when someone joins the server (also mention them)
#client.event
async def on_member_join(member):
print('welcome!'f'{member}')
the only thing i want to change is this should be displayed in the general channel (its printing it in the terminal now) and that instead of only displaying the person's name i want it to mention them.
Thank you for your help!
to send a message to a channel you need to get the channel and then send the message to there, you can get the channel using get_channel
client.get_channel(1234567890)# change to your channel id
or using discord.utils.get incase you want to use name instead
discord.utils.get(member.guild.channels, name="welcome")
and for mention, discord.py has provided us with member.mention
await channel.send(member.mention)
and combining both things we can make this
#client.event
async def on_member_join(member):
channel = client.get_channel(1234567890) # change to your channel id
await channel.send(f"Welcome {member.mention}!")
print(f'{member.name} joined the server')
I am using repl.it to develop a bot. I am trying to make a command that makes the bot behave like this:
Someone: !slap #someoneelse
Bot: #Someone slapped #someoneelse
How can I get the bot to mention #someone without using ID? Multiple people will use the command and I can't just use ID since it will only work with one person. I haven't found anything that helped me, and the documentation was no help either. Hopefully, I can get help! Thank you.
Users and members have a .toString() method that is automatically called every time they are concatenated with a string: that means that if you type "Hey " + message.author you will get "Hey #author"
That's how I would do the command:
// First store the mentioned user (it will be undefiend if there's none, check that)
let mentionedUser = message.mentions.users.first();
// Reply by directly putting the User objects in the string:
message.channel.send(`${message.author} slapped ${mentionedUser}`);