(discord.py)如何让我的漫游器随机回复DM?

时间:2020-06-10 15:04:57

标签: python python-3.x discord discord.py

例如,当某人DM我的机器人时,它说“你好”或“你为什么要DM机器人..?” 我用以下代码尝试过此操作:

@client.event
async def on_message(message: discord.Message):
    if message.guild is None and not message.author.bot:
        with open('dmresponses.txt') as input_file:
            long_list = [line.strip() for line in input_file]
        await message.author.send(random.choice(long_list))

成功了。但是,我的命令“ m!help”和“ m!about”停止了工作。正确的做法是什么?

1 个答案:

答案 0 :(得分:2)

添加on_message事件时,需要处理以下命令:

@client.event
async def on_message(message): # no need to define the type
    await client.process_commands(message)
    # rest of the code here

参考: