discord.py 新手,在尝试获取用户名时立即遇到障碍。
这是我的代码:
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix = '!', intents=intents)
user = discord.Member
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type = discord.ActivityType.watching, name = 'Test!'))
print(f"""Bot is on! Hello World :D!
Logged in as {client.user}
ID: {client.user.id}""")
@client.command()
async def t(ctx):
await ctx.send(user.name)
它不打印名称,而是打印“
也尝试过使用discord.User,但没有成功。
首先,
discord.Member
是一个类对象,当前没有任何内容分配给它。如果您想获取特定用户,可以使用 user = await client.fetch_user(user_id)
,然后使用 await ctx.send(user.display_name) #or username
最后您还需要一个
client.run("TOKEN")
。