为了账号安全,请及时绑定邮箱和手机立即绑定

我无法在discord.py 中发出命令

我无法在discord.py 中发出命令

拉莫斯之舞 2023-07-18 09:40:50
所以我在discord.py 上遇到了问题。我想发出命令来踢/禁止人们。我一开始尝试了这个,但没有成功,所以我去检查命令是否对我有用。显然事实并非如此。我已经尝试了一切,但没有任何效果。import discordfrom discord.ext import commandsclient = discord.Client()bot = commands.Bot(command_prefix='!')Token = 'TOKEN'@bot.command(pass_context=True)async def test(ctx):    await ctx.send('test')client.run(Token)我在频道上输入 !test 但没有任何反应。我基本上已经尝试了一切。我改变了前缀,done:,@bot.command(name='test)基本上你能想到的一切。什么都不起作用。我想知道我是否遗漏了一些重要的东西。就像我必须先下载一些东西,还是我在代码中遗漏了一些东西,或者我需要启用哪些权限。我已经查看了discord py API 参考资料。任何事情都会有帮助谢谢。
查看完整描述

1 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

你的问题是因为bot = commands.Bot(). 您可以使用以下代码代替:


import discord

from discord.ext import commands


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

@client.command()

async def test(ctx):

await ctx.send('test')

client.run(token)

所以你只需删除bot = commands.Bot()然后替换@bot.command()为@client.command.


查看完整回答
反对 回复 2023-07-18
  • 1 回答
  • 0 关注
  • 69 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信