如果代码正确,我想创建一个bot,bot会邀请我访问特定的服务器。 但它有错误
这是我的密码:
@client.command()
async def invite(ctx, *, code):
if code == "12320001":
guild = "851841115896152084"
invite = await ctx.guild.create_invite(max_uses=1)
await ctx.send(f"Here's your invite : {invite}")
else:
await ctx.send(f"Code is wrong!")
和错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'create_invite'
您需要一个
Channel
对象来创建invite,因为Guild
类没有create_invite()
方法。您可以使用下面给出的代码。请注意,服务器应该至少有一个通道正如错误所示,
ctx.guild
是None
。这通常发生在调用DM中的命令而不是服务器中的命令时,因为DMs中显然没有服务器根据您从未使用过的
guild
变量这一事实判断,我假设您试图邀请人们加入而不是公会ctx.guild
是None
,这就是为什么会出现此异常在调用
invite
函数时,可以在将ctx
作为参数传递之前检查ctx.guild
的值相关问题 更多 >
编程相关推荐