如何创建一个在Python中赋予角色的不和谐机器人?

2024-05-19 00:03:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个不和谐的bot,为Python中的成员提供角色。

我试过这个:

@async def on_message(message):
     if message.content == "give me admin"
           role = discord.utils.get(server.roles, name="Admin")
           await client.add_roles(message.author.id, role)

Tags: 角色messageasyncifadminondefbot
1条回答
网友
1楼 · 发布于 2024-05-19 00:03:27
import discord
from discord.utils import get

client = discord.Client()

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content == 'give me admin':
        role = get(message.server.roles, name='Admin')
        await client.add_roles(message.author, role)

我认为这应该管用。的文档是here

您还可以使用discord.ext.commands扩展名:

from discord.ext.commands import Bot
import discord

bot = Bot(command_prefix='!')

@bot.command(pass_context=True)
async def addrole(ctx, role: discord.Role, member: discord.Member=None):
    member = member or ctx.message.author
    await client.add_roles(member, role)

bot.run("token")

相关问题 更多 >

    热门问题