Discord.py Bot - 用户信息消息
Discord.py Bot - User info message
我正在 Python 中制作一个 Discord 机器人,目前,我想添加一个功能,当使用 _userinfo
命令时,机器人将发送有关用户的一般信息(他加入 Discord 的日期) , 他加入此服务器的日期, 他的昵称和他的头像)
我目前有这个代码:
if message.content.startswith("_userinfo"):
emb14 = discord.Embed(
title=f"{message.author.mention} info",
colour=discord.Colour.dark_blue()
)
emb14.set_image(url=message.author.avatar_url)
emb14.add_field(name=f"{message.author.mention}", value=f"{message.author}", inline=True)
await message.channel.send(embed=emb14)
但后来我收到了这条消息:
问题是昵称是ID(但不是nickname#0000
)而且我不知道如何添加服务器加入日期和Discord加入日期。有什么想法吗?
尝试将 {message.author.mention}
更改为 <@{message.author.id}>
。另外请注意,在标题和页脚中提及是无效的。
提及在 discord Embed
中无法正常工作,请检查此 。
要获取服务器加入日期和discord加入日期,您可以使用created_at
和joined_at
user
上的属性分别为
请仔细阅读下面的代码,
import discord
client = discord.Client()
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message(message):
if message.content.startswith("_userinfo"):
emb14 = discord.Embed(
title=f"@{message.author} info:",
colour=discord.Colour.dark_blue()
)
emb14.set_image(url=message.author.avatar_url)
emb14.add_field(name=f"Name", value=f"{message.author}", inline=True)
emb14.add_field(name=f"Discord Joined date", value=f"{message.author.created_at}", inline=True)
emb14.add_field(name=f"Server Joined date", value=f"{message.author.joined_at}", inline=True)
await message.channel.send(embed=emb14)
client.run('YOUR TOKEN')
输出:
我正在 Python 中制作一个 Discord 机器人,目前,我想添加一个功能,当使用 _userinfo
命令时,机器人将发送有关用户的一般信息(他加入 Discord 的日期) , 他加入此服务器的日期, 他的昵称和他的头像)
我目前有这个代码:
if message.content.startswith("_userinfo"):
emb14 = discord.Embed(
title=f"{message.author.mention} info",
colour=discord.Colour.dark_blue()
)
emb14.set_image(url=message.author.avatar_url)
emb14.add_field(name=f"{message.author.mention}", value=f"{message.author}", inline=True)
await message.channel.send(embed=emb14)
但后来我收到了这条消息:
问题是昵称是ID(但不是nickname#0000
)而且我不知道如何添加服务器加入日期和Discord加入日期。有什么想法吗?
尝试将 {message.author.mention}
更改为 <@{message.author.id}>
。另外请注意,在标题和页脚中提及是无效的。
提及在 discord Embed
中无法正常工作,请检查此
要获取服务器加入日期和discord加入日期,您可以使用created_at
和joined_at
user
上的属性分别为
请仔细阅读下面的代码,
import discord
client = discord.Client()
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message(message):
if message.content.startswith("_userinfo"):
emb14 = discord.Embed(
title=f"@{message.author} info:",
colour=discord.Colour.dark_blue()
)
emb14.set_image(url=message.author.avatar_url)
emb14.add_field(name=f"Name", value=f"{message.author}", inline=True)
emb14.add_field(name=f"Discord Joined date", value=f"{message.author.created_at}", inline=True)
emb14.add_field(name=f"Server Joined date", value=f"{message.author.joined_at}", inline=True)
await message.channel.send(embed=emb14)
client.run('YOUR TOKEN')
输出: