![](/img/trans.png)
[英]Is there a way to make a discord bot do something automatically (without message)?
[英]Is there a way to automatically reply/react to a Discord bot's message (Mudae)?
如果消息包含我想要的句子或值,我正在嘗試制作一個程序來響應或響應 Discord 機器人的消息。
我想到的機器人是 Mudae,一個動漫人物扭蛋生成器。 該程序應鍵入“message.react(":heart:")",或者如果我想要的角色確實出現,則單擊默認聲明反應
你必須使用:
on_message
事件獲取消息Member.bot
或Member.id
Message.add_reaction
添加對消息的反應Messageable.send
回復消息這是一個簡單的例子:
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_message(message):
if not message.author.bot: #Check if author is not a bot
return
if ':heart:' in message.content:
message.add_reaction('❤️')
elif 'hello' in message.content:
message.channel.send(f'Hi {message.author.mention} :)')
await bot.process_commands(message)
PS: on_message
事件會覆蓋命令,因此您需要await bot.process_commands(message)
才能將命令與on_message
事件一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.