【问题标题】:I can't run any command discord.py我无法运行任何命令 discord.py
【发布时间】:2021-06-09 01:21:27
【问题描述】:

所以我一直在为不和谐创建一个机器人,所以我一直在关注许多教程,但我唯一的命令不会运行。所以这是我的代码:

import discord
import os
from discord.ext import commands

client = discord.Client()
bot = commands.Bot(command_prefix = "_")

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("salut le bot"):
        await message.channel.send("Salut, je suis Bapo Bot, pour vous servir !")
    if message.content.startswith("merci fréro"):
        await message.channel.send("De rien mon gars !")
    if str(message.channel) == "uniquement-des-images" and message.content != "":
        await message.channel.purge(limit=1)
        print('Message :', (message.content), 'from', (message.author), 'deleted successfully.')

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print(discord.__version__)
    print('------------------')

@bot.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run(os.environ['BOT_TOKEN'])

此代码没有给出任何错误。 起初我认为client = discord.Client() 正在创建错误,但是当我删除它时,整个机器人不再工作了。我尝试更改 bot 前缀或更改现在称为 bot 的东西的名称(我仍然是 python 中的菜鸟,所以我不知道这个东西叫什么),现在我被卡住了。

编辑:由于答案已被版主(?)删除,这是解决方案。不能将on_message 函数与命令函数同时使用。

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您需要将await client.process_commands() 添加到您的 on_message 事件中!

    我个人将我的留在方法的底部!

    【讨论】:

    • 它正在创建此错误 ``` 2020-08-18T11:11:44.141984+00:00 app[worker.1]: File "bot.py", line 22 2020-08-18T11 :11:44.142009+00:00 app[worker.1]: 等待 client.process_commands() 2020-08-18T11:11:44.142014+00:00 app[worker.1]: ^ 2020-08-18T11:11: 44.142015+00:00 app[worker.1]: IndentationError: unindent 不匹配任何外部缩进级别 2020-08-18T11:11:44.193756+00:00 heroku[worker.1]: 进程以状态 1 退出```
    • 这是一个缩进错误IndentationError: unindent does not match any outer indentation level 。你没有正确缩进。确保 await client.process_commands 在 on_message 块内。
    猜你喜欢
    • 2021-01-05
    • 2022-10-25
    • 2019-04-15
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多