Discord Bot - 在Message,Python之后给角色

问题描述 投票:0回答:1

我正在尝试制作一个简单的discord bot,它在给机器人一定的命令后给用户一个角色

在命令!角色上,用户应该获得一个名为Beta的角色

我第一次尝试这个:

from discord_webhook import DiscordWebhook, DiscordEmbed
import discord
from discord.ext.commands import Bot
from discord.ext import commands


client = commands.Bot(command_prefix = "!")
Client = discord.Client()

@client.event
async def on_message(message):
    member = message.author
    if member.bot:
        return
    if message.attachments:
        return
    print(message.content)
    print(str(message.author))


    if "role" in message.content:
        embed=discord.Embed(title="Giving role.", color=0x00ff40)
        await message.channel.send(message.channel, embed=embed)
        role = discord.utils.get(server.roles, name="Beta")
        await client.add_roles(message.author, role)


client.run("BOT TOKEN")

但我总是遇到以下问题:AttributeError: 'list' object has no attribute 'roles'

非常感谢您花时间阅读本文以及您是否可以帮助我。谢谢

python discord discord.py
1个回答
1
投票

当你这样做时:

role = discord.utils.get(server.roles, name="Beta")

你必须使用

message.guild.roles

代替:

server.roles

要访问角色列表,较新的不和谐版本使用公会而不是服务器,以避免与语音服务器混淆。

© www.soinside.com 2019 - 2024. All rights reserved.