Discord.py @bot.command()不';t运行-未显示任何错误
我试图让我的机器人在用户运行命令“!hi”时响应“hi”。问题是命令没有运行,也没有显示错误。.py文件中的代码与显示的完全相同(除了用实际的令牌替换令牌)如果您正在运行Discord.py @bot.command()不';t运行-未显示任何错误,discord.py,Discord.py,我试图让我的机器人在用户运行命令“!hi”时响应“hi”。问题是命令没有运行,也没有显示错误。.py文件中的代码与显示的完全相同(除了用实际的令牌替换令牌)如果您正在运行client,并使用bot.command()装饰命令,则必须使用discord.client或commands.bot,而不是两者都使用 导入不一致 从discord.ext导入命令 意图=不和谐。意图。全部() bot=commmands.bot(command\u前缀=command.when\u提到\u或(“!”),in
client
,并使用bot.command()
装饰命令,则必须使用discord.client
或commands.bot
,而不是两者都使用
导入不一致
从discord.ext导入命令
意图=不和谐。意图。全部()
bot=commmands.bot(command\u前缀=command.when\u提到\u或(“!”),intents=intents)
@bot.command()
异步def hi(ctx):
等待ctx发送(“Hi”)
#您还可以将事件与'commands.Bot'一起使用`
@机器人事件
_ready()上的异步定义:
打印(“就绪”)
bot.run(“令牌”)
这里的问题是您同时使用discord.Client和commands.Bot
以下是修复方法:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@bot.command()
async def hi(ctx):
await ctx.send("hi")
client.run(TOKEN)
import discord
from discord.ext import commands
TOKEN = "Your Token"
Intents=discord.Intents.all()
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), Intents=Intents)
@bot.command()
async def hi(ctx):
await ctx.send("hi")
client.run(TOKEN)