【问题标题】:discord.py commands aren't working (no errors given)discord.py 命令不起作用(没有给出错误)
【发布时间】:2020-12-30 02:09:56
【问题描述】:

(以下代码仅用于娱乐目的。请勿在不和谐服务器中使用此代码)。老实说,我不知道为什么它不起作用。当我使用完全相同的代码打开一个新的 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.

【问题讨论】:

  • edit 展示你是如何做到这一点的:“把它和所有代码放在我的文件中”。也许您没有导入正确的模块或调用正确的函数。

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2019-01-26
    • 2020-08-16
    • 2019-07-23
    • 1970-01-01
    相关资源
    最近更新 更多