当我运行注册命令时没有任何反应。我已经尝试了一切,但没有任何帮助( 导入不和谐 导入环境 从discord.ext导入命令
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=discord.Intents.all())
TOKEN = env.discord_token("DISCORD_TOKEN")
@client.event
async def on_ready():
print("Im ready to go : {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("!instagram"):
await message.channel.send('https://www.instagram.com')
if message.content.startswith("!youtube"):
await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")
#Dont work
@client.command
async def register(ctx, arg1, arg2):
await ctx.send(arg2, arg1)
@client.event
async def on_member_join(member):
role_1 = member.guild.get_role(807733964214321878)
await member.add_roles(role_1)
client.run(TOKEN)
最佳答案
其实不然
@client.command
正确的使用方法是..
@client.command(name="Command name", description="Command Description")
“名称”和“描述”参数是可选的。
还有一件事... 由于您使用了“on_message”事件.. 这样做...
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("!instagram"):
await message.channel.send('https://www.instagram.com')
if message.content.startswith("!youtube"):
await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")
else:
await client.process_commands(message)
根据我的说法,你的整个代码:
import discord
import env
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=discord.Intents.all())
TOKEN = env.discord_token("DISCORD_TOKEN")
@client.event
async def on_ready():
print("Im ready to go : {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("!instagram"):
await message.channel.send('https://www.instagram.com')
elif message.content.startswith("!youtube"):
await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")
else:
await client.process_commands(message)
@client.command(name='reg')
async def register(ctx, arg1, arg2):
await ctx.send(arg2, arg1)
@client.event
async def on_member_join(member):
role_1 = member.guild.get_role(807733964214321878)
await member.add_roles(role_1)
client.run(TOKEN)
关于python - discord.py 为什么 @client.command 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66839150/