【问题标题】:how to mention users with discord bot in python如何在 python 中使用 discord bot 提及用户
【发布时间】:2021-10-24 06:19:11
【问题描述】:
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 @(提到的用户)'并获得机器人的响应'@(作者提到的)想要高五你@(提到的用户)'

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

提前感谢您的任何帮助

【问题讨论】:

  • 也许this线程可以帮助你

标签: python discord bots member mention


【解决方案1】:

我正在使用 用户 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')

【讨论】:

    猜你喜欢
    • 2020-07-27
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2019-11-19
    • 2020-12-18
    相关资源
    最近更新 更多