我有角色的ID,但我需要找到一种获取其名称的方法。我尝试使用ctx.guild.get_role("roleid").name
,但似乎没有给出好的数据类型。文字频道和用户也是如此。
答案 0 :(得分:1)
您可以使用discord.utils.get
:
from discord.ext import commands
from discord.utils import get
def getter(iterables, id: int):
data = get(iterables, id=id)
return data
@bot.command()
async def display_data(ctx):
#Get roles
role = getter(ctx.guild.roles, id)
#Get channels
channel = getter(ctx.guild.channels, id)
#Get users
user = getter(ctx.guild.members, id)
await ctx.send(f"Data found:\nRole:{role.name}\nChannel:{channel.name}\nUser:{user.name}")
数据类型:
Member
对象Role
对象TextChannel
或VoiceChannel
对象