簡體   English   中英

如何讓我的 python discord bot 檢測到命令中提到的某個用戶?

[英]how can I make my python discord bot detect a certain user being mentionned in a command?

我正在嘗試獲取一個命令來處理異常,當 bot 本身被 ping 時,會發送不同的消息,而不是普通的普通消息。 而且我似乎無法在 discord.py 中找到對我有利的某個命令,有什么建議嗎?

@bot.command()
async def fight(ctx):
    if (insert the scanned mention == 'insert discord bot ping'):
        await ctx.send('message')
        await ctx.send('another message')```

您可以使用ctx.message.mentions獲取所有提到的用戶的ctx.message.mentions 如果您擁有該人的Member / User實例,您可以只執行member.mentioned_in(message) ,或者在您的情況下:

if client.user.mentioned_in(message):
    # do something here

如果您沒有Member實例,您可以遍歷ctx.message.mentions ,並檢查每一個以查看它們是否是您需要檢查的那個。

id = 12345678910  # The Discord id of the member you want to check
for user in ctx.message.mentions:
    if user.id == id:
        # do something here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM