[英]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 加入日期。 有任何想法嗎?
提及discord Embed
不能正常工作,請檢查此stackoverflow 答案。
要獲取服務器加入日期和不和諧加入日期,您可以分別在user
上使用created_at
和joined_at
屬性。
請仔細閱讀下面的代碼,
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')
嘗試將{message.author.mention}
更改為<@{message.author.id}>
。 另請注意,在標題和頁腳中提及無效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.