1 回答

TA贡献1810条经验 获得超4个赞
为此,您需要将User
对象转换为Member
对象。这样,您就可以调用该add_roles
方法。这是一种方法:
import discord
from discord.ext import commands
from discord.utils import get
@client.event
async def on_message(message):
# Check if message was sent by the bot
if message.author == client.user:
return
# Check if the message was a DM
if message.channel.type != discord.ChannelType.private:
return
user_code = "some code sent via email"
if message.content == user_code:
new_guild = client.get_guild(int(GUILD_ID))
member = new_guild.get_member(message.author.id)
role = new_guild.get_role(int(DISCORD_ROLE))
await member.add_roles(role)
response = "You can now use the Discord Server."
await message.channel.send(response)
添加回答
举报