[英]How can i make my Discord bot mention a specific person in the channel?
So i just recently started learning how to develop a Discord bot with Python and im pretty confused on how to make my bot mention people after a specific message is sent.所以我最近才开始学习如何用 Python 开发一个 Discord 机器人,我对如何让我的机器人在发送特定消息后提及人们感到非常困惑。 What im trying to do is when i write "call George" in a specific channel, i want my bot to mention @George's_name and maybe something like "are you here?"
我想要做的是,当我在特定频道中写下“呼叫乔治”时,我希望我的机器人提及@George's_name 以及诸如“你在吗?”之类的内容。 after the mention.
提到之后。
From what i have seen, everyone says that in order to mention someone i need to copy his USER_ID and write something like <@USER_ID>, but i still dont know how the syntax is.据我所见,每个人都说为了提及某人,我需要复制他的 USER_ID 并编写类似 <@USER_ID> 的内容,但我仍然不知道语法如何。
async def on_message(self, message):
if message.author == self.user:
return
if message.content == 'Call George':
await message.channel.send('Hey ', <@USER_ID> ,' are you here?')
As you can tell, whenever someone says "Call George", i want the bot to mention george and ask him if he is here.如您所知,每当有人说“呼叫乔治”时,我都希望机器人提及乔治并询问他是否在这里。 When i try to run my code though it tells me Invalid Syntax and highlights the <@USER_ID> part.
当我尝试运行我的代码时,它告诉我语法无效并突出显示 <@USER_ID> 部分。
You have said in a comment that you have the id stored in a variable somewhere, you can use string.format(user_id) to ping the user The reason it was giving an error is because you were using commas, Whilst this would work in print() you need to concatenate the string if you want to use send() Hope this helped, Sorry for misinterpreting.您在评论中说您将 id 存储在某个变量中,您可以使用 string.format(user_id) ping 用户它给出错误的原因是因为您使用了逗号,虽然这可以用于打印() 如果你想使用 send() 你需要连接字符串希望这有帮助,对不起误解。
async def on_message(self, message):
if message.author == self.user:
return
if message.content == 'Call George':
await message.channel.send('Hey ' + "<@{}>".format(userid) + ' are you here?')
if you have one person in mind and you want the function to only ping that person you can do this如果您有一个人,并且您希望该功能仅 ping 那个人,您可以执行此操作
async def on_message(self, message):
if message.author == self.user:
return
if message.content == 'Call George':
await message.channel.send('Hey ' + "<@123456>" + ' are you here?')
replace "123456" with their actual id.用他们的实际 ID 替换“123456”。
You should use this syntax:您应该使用以下语法:
await message.channel.send("<@user_id>, are you here?")
where user_id is George's id.其中 user_id 是 George 的 id。 Example:
例子:
await message.channel.send("<@668503061970288660>, are you here?")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.