我目前正在开发一个机器人,但由于某些原因,我的命令根本无法工作,但事件却可以工作。我的前缀和令牌存储在json中,所以我也会确保包含该文件。
Main.py。(忽略导入,它们在机器人的其他地方使用)
import discord
from discord.ext import commands
import json
import random
import re
from datetime import datetime
import requests
import ctypes
from colorama import Fore, Style, init
import os
token = json.loads(open("config.json").read())['token']
prefix = json.loads(open("config.json").read())['prefix']
bot = discord.Client()
bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")
@bot.command()
async def spam(ctx, amount: int, spam):
await ctx.message.delete()
for s in range(amount):
await ctx.send(spam)
bot.run(token)
config.json:(忽略导入,它们在机器人的其他地方使用。
{
"token": "token-here",
"prefix": "$",
}
解决方案:
确保你有 await client.process_commands(message)
在你的on_message事件的最后。