【发布时间】:2020-06-14 23:43:52
【问题描述】:
我正在尝试使用命令来使用 DiscordPy 赋予特定角色,但我使用的每个 search 都会给我带来相同的答案,但无济于事:1、2、3。
显然,我遗漏了一个基本部分,但我不知道是什么。 documentation 涵盖了有一个add_roles 命令,但这并没有说明如何将它用于其他用户。事实上,尝试await add_roles("Team Captain") 会给出错误NameError: name 'add_roles' is not defined。
我在这里缺少什么?为什么add_roles 在记录时不存在,以及如何针对不同的用户使用它。
这是我目前拥有的(部分),但显然不起作用:
import discord, discord.utils, random, os, re, json
from discord.ext import commands
from discord.utils import get
from dotenv import load_dotenv
client = discord.Client()
load_dotenv()
key = os.getenv('DISCORD_KEY')
@client.event
async def on_message(message):
if message.author == client.user:
return
print('Message from {0.author}: {0.content}'.format(message))
#Want these commands in the right channel
if str(message.channel).lower().startswith("bot"):
if message.content.lower().startswith("$addcaptain"):
if len(message.mentions) == 0:
await message.channel.send("Needs a user to give Team Captain role.")
return
else:
await add_roles("Team Captain") #Doesn't work, and I assume would be against the user who sent the message, not the mentioned one
client.run(key)
key = os.getenv('DISCORD_KEY')
【问题讨论】:
标签: python-3.x discord.py