如何同时使用不和谐的bot命令和事件? [英] How to use discord bot commands and event both?
本文介绍了如何同时使用不和谐的bot命令和事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个机器人来侦听服务器中编写的消息,同时接受命令.
I need to make a bot that listen for messages written in a server, and at the same time accept commands.
# Create the Discord client
client = discord.Client()
client = commands.Bot(command_prefix = '!')
client.remove_command('help')
@client.event
async def on_ready():
print('ready')
@client.event #ricerca messaggi
async def on_message(message):
# Ignore messages made by the bot
if(message.author == client.user):
return
a = ''
a += message.embeds[0]["description"]
if a == 'abcdef':
print(' aaaaa ')
@client.command()
async def hello():
await client.say('hello')
client.run('token')
如何使它起作用?我认为问题在于该机器人在第一次事件中会继续循环...我读到有关sub_process的信息,但我不知道如何使用它.
How can I make it works? I think the problem is that the bot continue cycling in the first event... I read about sub_process but I do not understand how to use it.
推荐答案
您将需要在on_message的末尾添加process_commands().这是因为覆盖默认的on_message禁止命令运行.
You will need to add process_commands() at the end of your on_message. This is because overriding the default on_message forbids commands from running.
@client.event #ricerca messaggi
async def on_message(message):
# Ignore messages made by the bot
if(message.author == client.user):
return
a = ''
a += message.embeds[0]["description"]
if a == 'abcdef':
await message.channel.send(' aaaaa ')
await client.process_commands(message)
这篇关于如何同时使用不和谐的bot命令和事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文