簡體   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