[英]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.