Discord Python - 有没有办法让机器人从另一个机器人读取命令,或者我们是否必须将整个事件更改为 on_message 事件?

时间:2021-05-11 09:03:08

标签: python discord

我们想让我们的一个机器人在我们的另一个机器人调用它们时运行命令(在聊天中写入它们)。

我们目前使用当前的结构,它不会对其他机器人发出的命令做出反应:

@self.client.command(pass_context = True)
async def play(ctx, channel, url):
    #Execute command
    

为了让我们的机器人从另一个机器人读取命令,我们是否必须将其更改为这个?:

@self.client.event  
async def on_message(message):
    #Execute command

或者有什么方法可以让我们的机器人执行来自另一个机器人的命令?

1 个答案:

答案 0 :(得分:0)

你可以把命令放在检查作者是不是机器人之前,试试这个格式

@client.event 
async def on_message(message):

    if message.content == '!ex1':
        # Message without bot check
        await message.channel.send('You could be a bot!')

    if message.author == client.user:
        return # Don't respond if the author is a bot

    if message.content == '!ex2':
        # Message with bot check
        await message.channel.send('You are a user!')
相关问题