当我运行 register 命令时没有任何反应。我已经尝试了一切,但没有任何帮助( 进口不和谐 导入环境 from 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)
答案 0 :(得分:2)
其实不是
@client.command
正确的使用方法是..
@client.command(name="Command name", description="Command Description")
'name' 和 '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)
答案 1 :(得分:1)
我很确定我知道答案。您正在使用:
@Client.command
您应该在 command
后使用括号,即
你应该使用:
@Client.command()
我认为这会奏效。如果这不起作用,请告诉我,以便我再次检查。
谢谢!
答案 2 :(得分:0)
上面的答案是不正确的 - 是的,推理是正确的,但请记住:Python 是大写敏感的。
你犯的错误很简单,我什至没有注意到。
你需要做的是:
@client.command()
现在,你可能会说上面的答案和我在这里写的答案没有区别,但是如果你仔细看,在我上面的答案中有一个大写字母 C。
是。小心。在。首都。字母。
此外,括号内的名称和描述是可选的。
如果你需要更多帮助,请私信我(officer grr#6609)