英文:
How to get avatar in on_member_join using python discord bot?
问题
I want to get avatar of member in on_member_join
using python discord bot as we know that it only takes member I can't use ctx so how can I get the avatar image. This is required because I want to make welcome embeds like mee6 or Koya. Can anyone help me to solve this problem
we know ctx is required to get avatar
avatmember = ctx.author
await ctx.send(avatmember.avatar.url)
if we write it as
await channel.send(member.avatar.url)
it shows
await channel.send(member.avatar.url)
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'url'
My code
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
robota = commands.Bot(command_prefix=".", intents=intents, help_command=None)
clients = discord.Client(intents=intents)
@robota.event
async def on_member_join(member):
channel = robota.get_channel(Channel_ID)
embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
embed.set_thumbnail(url=member.avatar.url)
await channel.send(embed=embed)
英文:
Sir,
I want to get avatar of member in on_member_join
using python discord bot as we know that it only takes member I can't use ctx so how can I get the avatar image. This is required because I want to make welcome embeds like mee6 or Koya. Can anyone help me to solve this problem
we know ctx is required to get avatar
avatmember = ctx.author
await ctx.send(avatmember.avatar.url)
if we write it as
`
await channel.send(member.avatar.url)
it shows
await channel.send(member.avatar.url)
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'url'
My code
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
robota = commands.Bot(command_prefix=".", intents=intents, help_command=None)
clients = discord.Client(intents=intents)
@robota.event
async def on_member_join(member):
channel = robota.get_channel(Channel_ID)
embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
embed.set_thumbnail(url=member.avatar.url)
await channel.send(embed=embed)
答案1
得分: 1
你在声明函数时是否传递了member
?如果你想创建一个带有成员头像的欢迎消息,可以使用类似以下方式 -
@bot.event
async def on_member_join(member):
channel = bot.get_channel(WELCOME_CHANNEL_ID)
await channel.send("欢迎!")
embed = discord.Embed(title=f"欢迎加入服务器,{member.name}!")
embed.set_thumbnail(url=member.avatar.url)
await channel.send(embed=embed)
英文:
Did you pass member
when declaring the function?
If you want to create a welcome message with member avatar then you can use something like this -
@bot.event
async def on_member_join(member):
channel = bot.get_channel(WELCOME_CHANNEL_ID)
await channel.send("Welcome!")
embed = discord.Embed(title=f"Welcome to the server, {member.name}!")
embed.set_thumbnail(url=member.avatar.url)
await channel.send(embed=embed)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论