我有这个 python 代码,但斜杠命令不起作用。当我运行代码时,机器人显示在线,但斜杠命令不起作用,并且控制台中没有记录任何命令:
import discord #Imports the discord module.
from discord.ext import commands #Imports discord extensions.
#The below code verifies the "client".
client = commands.Bot(command_prefix='-t', intents=discord.Intents.all())
#The below code stores the token.
token = "[TOKEN]"
'''
The below code displays if you have any errors publicly. This is useful if you don't want to display them in your output shell.
'''
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Please pass in all requirements :rolling_eyes:.')
if isinstance(error, commands.MissingPermissions):
await ctx.send("You dont have all the requirements :angry:")
#The below code bans player.
@client.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member, *, reason = None):
await member.ban(reason = reason)
#The below code unbans player.
@client.command()
@commands.has_permissions(administrator = True)
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split("#")
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
return
#The below code runs the bot.
client.run(token)
我尝试在开始时删除
intents=intents
块,但它给出了错误,当我将其更改为现在的样子时,没有任何变化。
机器人拥有所有特权网关意图。