在尝试调用命令后,我试图让我的机器人扮演角色,但是我不确定什么是正确的命令。我在网上搜索,但我尝试的每一个都出错。有人知道命令的正确形式吗?
代码:
#iports the discord folder and commands for our bot
import discord
from discord.ext import commands
from discord import Member
from discord.ext.commands import has_permissions
from discord.ext import tasks
#sets the command prefix
Client = commands.Bot(command_prefix = ";")
#print Nuggie is ready in the console when the bot is activeted
@Client.event
async def on_ready():
await Client.change_presence(status=discord.Status.online, activity = discord.Game("With Your Mom"))
print("Nuggie is ready")
@Client.command()
async def setup_verification(ctx, arg):
channel_id = 768983636296204318
await clear(ctx)
Text = "send ;verify to this message to get verified and get access to the server!"
embedVar = discord.Embed(title = "Verify your identity", description = Text, color = 0xC311EF)
embedVar.add_field(name = "\u200B", value = "\u200B")
embedVar.add_field(name = "This proccess in crucial for the server.", value = "Without this, the server is exposed to raids." , inline=False)
await ctx.channel.send(embed=embedVar)
#await ctx.send(Text)
@Client.command()
async def verify(ctx):
channel = 768983636296204318
if discord.TextChannel.id == channel:
clear()
await ctx.send("This message is not available in this channel! Pls only use command where it's supposed to be!")
else:
author = ctx.message.author.name
#Role = discord.utils.get(author.server.roles, name="Member")
await Message.add_roles(author, "Member")
#roleRemove = get(user.server.roles, name='member')
await Client.remove_role(author, "Unverified")
await ctx.send(f"{author} you are verified!")
await asyncio.sleepdelay(s = 60)
clear(ctx, 2)
Client.run('My_Token')
运行验证时出现的错误是:
Ignoring exception in command verify:
Traceback (most recent call last):
File "C:\Users\roy\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\roy\Desktop\Folders\Atom\Discord Bot\Nuggie.py", line 40, in verify
await Message.add_roles(author, "Member")
NameError: name 'Message' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\roy\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\roy\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\roy\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'Message' is not defined
答案 0 :(得分:0)
您需要import grpc
对象,并且可以在其上调用Member
。 add_roles()
是您的Member对象,现在您需要获取Role对象。有多种获取Role对象的方法。您可以使用Guild.get_role(role_id)
通过ID获取它,也可以使用discord.utils.get
ctx.author
现在,由于有了成员对象和角色对象,您只需在成员对象上调用Member.add_roles()
。
memberRole = discord.utils.get(ctx.guild.roles, name='Member')
删除Unverified角色的方法相同,但您调用Member.remove_roles()