本文介紹了如何制作一個在 Python 中提供角色的不和諧機器人?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想創建一個 Discord 機器人,在 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
擴展:
You could also use the discord.ext.commands
extension:
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 中提供角色的不和諧機器人?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!