discord.py命令不起作用(未给出错误)

时间:2020-09-11 14:24:45

标签: python arrays python-3.x list python-2.7

(以下代码仅用于娱乐目的。请勿在不和谐的服务器中使用此代码)。老实说,我不知道为什么它不起作用。当我使用完全相同的代码打开一个新的python文件时,它可以工作。但是,如果我将其与所有代码一起放入文件中,则由于某种原因它不会。没有输出,没有错误。

from discord.ext import commands

#Settings
KICK_ON_MESSAGE = False

TOKEN = "Token goes here"


client = commands.Bot(command_prefix="/")



@client.event
async def on_ready():
    print('Logged in!')


@client.event
async def on_message(message):
    if KICK_ON_MESSAGE == True:
        member = message.author
        await member.kick()
        print(str(member)+' has been succesfully kicked!')


@client.command()
async def test(ctx):
    await ctx.send('hi!')



client.run(TOKEN)



Thanks in advance.

1 个答案:

答案 0 :(得分:0)

这可能是因为您没有在on_message事件中处理命令。 只需在await client.process_commands(message)事件(在if语句之外)的末尾添加on_message,它便会开始工作。

请阅读以下内容以供参考:https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working