简体   繁体   English

如何让我的 Discord 机器人提及频道中的特定人员?

[英]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.

相关问题 我怎样才能让我的 discord 机器人在键入时提到特定的人? - How can I make it so my discord bot mentions a specific person when they type? 如何让不和谐的机器人在命令中提及我和我提及的人 - How to get discord bot to mention me and the person i mention in the command 如何让我的 discord.py 机器人删除在特定频道上发送的每条消息? - How can I make my discord.py bot delete every message send on a specific channel? 如何让我的 discord 机器人回复提及? - How do I make my discord bot reply to a mention? 如何让我的 discord 机器人在 py 中提及没有 ID 的人? - How can I make my discord bot mention someone without the ID in py? 在 discord.py 我怎样才能让我的机器人命令只能在特定通道或特定服务器中使用? - in discord.py How can i make my bot that the commands only can be use in specific channel or specific server? 如何让我的 discord 机器人只回复特定频道的问题? - How to make my discord bot only reply question in specific channel? 如何制作一个 discord 机器人来记录特定频道的聊天记录? - How do I make a discord bot that logs chats in a specific channel? 当语音频道中的人说话时,我可以让 discord python 机器人识别吗? - Can I make a discord python bot recognize when a person in a voice channel talks? 如何让我的 Discord 机器人在特定 mp3 文件的时间长度内停留在语音通道中? - How do I make my Discord bot stay in the voice channel for the length of time of a specific mp3 file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM