【发布时间】:2023-02-22 06:08:49
【问题描述】:
基本上我使用的是 nextcord,它是 discord.py 的一个分支。总的来说,我对编程有点陌生,但由于我喜欢或已经有一段时间不和谐,并且想从事需要编程的职业,所以我说做一个像这样的小项目将是一个好的开始。
import asyncio
import nextcord
from nextcord.ext import commands
from nextcord.ext.commands import guild_only
@client.command()
@commands.has_role("Admin")
async def giverole(ctx, member : nextcord.Member, role : nextcord.Role):
if role in member.roles:
await member.add_roles(role, atomic = True)
embed8a = nextcord.Embed(description = f"Removed **{role}** from **{member}**", color = nextcord.Color.orange())
await ctx.send(embed = embed8a)
else:
await member.add_roles(role, atomic = True)
embed7a = nextcord.Embed(description = f"Added **{role}** to **{member}**", color = nextcord.Color.orange())
await ctx.send(embed = embed7a)
Anyways, my issue is that in the code below I am able to add one role to a user at a time, however not multiple. According to the nextcord/discord.py documentation, using the "Atomic = true" attribute should make this possible but I've gotten several errors. I've listed the most current one below.
Traceback (most recent call last): File "C:\Users\De'shon\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\bot.py", line 1381, in invoke await ctx.command.invoke(ctx) File "C:\Users\De'shon\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\core.py", line 948, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\De'shon\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\core.py", line 174, in wrapped raise CommandInvokeError(exc) from exc nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'tuple' object has no attribute 'id'
【问题讨论】:
标签: python discord discord.py nextcord