import discord
from discord import app_commands
import json
intents = discord.Intents().all()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@tree.command(name="subscribe")
async def the_command(interaction, itemid: str):
discid = int(interaction.user.id)
print(discid)
with open("data.json", "r") as file:
data = json.load(file)
if itemid in data:
role_id = data[itemid]["roleid"]
print(role_id)
guild = interaction.guild
print(guild)
member = await guild.fetch_member(discid)
print(member)
if member is not None:
role = guild.get_role(role_id)
if role is not None:
await member.add_roles(role)
await interaction.response.send_message(f"Role assigned for item ID: {itemid}")
else:
await interaction.response.send_message(f"Role for item ID {itemid} not found in the guild.")
else:
await interaction.response.send_message("You are not a member of this guild.")
else:
await interaction.response.send_message(f"Item ID {itemid} not found in the data.")
它返回的角色是NONE,说discord不承认它.
是的,我已经判断了unions 本身的ID,它是一个具有相同ID的现有角色,所以我很困惑
我做错什么了吗?