如何制作一个在Python中扮演角色的不和谐机器人? [英] How to make a discord bot that gives roles in Python?
本文介绍了如何制作一个在Python中扮演角色的不和谐机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个不和谐的bot,为Python中的成员赋予角色.
I want to create a discord bot that gives roles to members in 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)
推荐答案
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)
我认为这应该有效. discord.py 的文档是此处.
I think this should work. The documentation for discord.py is 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")
这篇关于如何制作一个在Python中扮演角色的不和谐机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文