Issue
New to discord.py, immediately hit a roadblock when trying to fetch a username from the user object.
EDIT: I'm also trying to find out how to utilize the User object, so I can access other useful information
Here's my code:
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)
Instead of printing the name as well, a name, it prints "<property object at 0x...>".
Tried using discord.User as well, no luck.
Solution
To start, discord.Member
is a class object, there is nothing assigned to it currently. If you want to fetch a specific user, you can use user = await client.fetch_user(user_id)
and then use await ctx.send(user.display_name) #or username
You also need a client.run("TOKEN")
at the end.
Answered By - Some Things
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.