繁体   English   中英

如何在 python 中使用 discord bot 提及用户

[英]how to mention users with discord bot in python

if message.content.startswith('!highfive'):
        channel = message.channel

        await channel.send('{0.author.mention} wants to high-five you'.format(message))

        def check(m):
            return m.content == 'yes' and m.channel == channel
      
        try:

            message = await client.wait_for('message', timeout=10.0, check=check)
            await channel.send('you accepted the highfive {0.author.mention}'.format(message))
            
        except asyncio.TimeoutError:
            await channel.send('you took too long to answer')

嗨,我对此很陌生,正在尝试创建一个简单的不和谐机器人

我可以让机器人提及作者,但是,我已经花了很长时间寻找,但仍然无法弄清楚如何提及用户。 我想使用命令'!highfive @(提到的用户)'并获得机器人的响应'@(作者提到的)想要高五你@(提到的用户)'

此外,如果超时错误不起作用,我无法生成对“是”和理想情况下的“否”的单独响应。

提前感谢您的任何帮助

我正在使用用户 ID在我的机器人中提及某人:

import string #very important import to send message with 'f' text function

if message.content.startswith('!highfive'):
        channel = message.channel
        user_id = message.author.id  #getting author id

        await channel.send(f'<@{user_id}> wants to high-five you'.format(message)) #i eddited this to use 'user_id' variable to mention user

        def check(m):
            return m.content == 'yes' and m.channel == channel
      
        try:

            message = await client.wait_for('message', timeout=10.0, check=check)
            await channel.send(f'you accepted the highfive <@{user_id}>'.format(message)) #mention eddit here too
            
        except asyncio.TimeoutError:
            await channel.send('you took too long to answer')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM