【发布时间】:2020-09-13 03:59:30
【问题描述】:
我正在尝试在 discord 中扮演一个全新的角色(使用 discord.py),但我尝试的一切都不起作用。我已经试过了
await guild.create_role(name("R3KT")) #NameError: name 'guild' not defined
和
author = ctx.message.author
await client.create_role(author.server, name="role name") #NameError: name 'ctx' not defined
我尝试将 ctx 和 guild 更改为“客户端”,但仍然没有成功。如果需要,我将发送整个代码(不包括不和谐名称和机器人密钥)
这是完整的代码:
import discord
token = "bot-key"
client = discord.Client()
@client.event
async def on_ready():
print("Bot is online and connected to Discord")
@client.event
async def on_message(message):
message.content = message.content.upper()
if message.author == client.user:
return
if message.content.startswith("AS HELLO"):
await message.channel.send("works")
elif message.content.startswith("AS CREATEROLE"):
if str(message.author) == "myDiscName#6969":
author = message.author
await discord.create_role(author.server, name="R3KT")
elif message.content.startswith("AS GIVEROLE"):
if str(message.author) == "myDiscName#6969":
print("give role")
client.run(token)
【问题讨论】:
-
你能在你的整个代码中发布(包括你的
on_message或命令事件) -
在这里,我发布了整个代码。希望你能找到任何缺陷。 (也正如我所说,我替换了光盘名称和机器人密钥)
标签: python-3.x discord discord.py