![](/img/trans.png)
[英]How do I get all user input as a string with my discord bot after they type a certain command?
[英]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.