本文介紹了如何在 discord.py 中獲取帶有 id 的用戶頭像?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試使用以下代碼,但沒有成功.
I tried using the following code but it didn't work.
@bot.command()
async def avatar(ctx,*, avamember):
user = bot.get_user(avamember)
await ctx.send(f"{user.avatar_url}")
對于遇到類似問題的任何人,雖然文檔中沒有提到,但 discord.Member 可以將用戶 ID 放在 @username 之外,因此不需要復雜的方法.
For anyone that had a similar problem, while not mentioned in the docs, discord.Member can take user ids aside from @username so there isn't any need for a complicated way.
推薦答案
我假設您在不和諧地使用 @UserNameHere 標記用戶.將該輸入作為成員對象要容易得多:)
I'm presuming you're Tagging the user with @UserNameHere in discord. It's much easier to take that input as a member Object :)
您也不需要將 url 括在引號中.
You also don't need to wrap the url in quotes.
如果它在 cog 中,則此代碼:
This code is if it is in a cog:
@commands.command()
async def avatar(self, ctx, *, avamember : discord.Member=None):
userAvatarUrl = avamember.avatar_url
await ctx.send(userAvatarUrl)
此代碼是否在主 bot.py 文件中:
This code is if it is in the main bot.py file:
@bot.command()
async def avatar(ctx, *, avamember : discord.Member=None):
userAvatarUrl = avamember.avatar_url
await ctx.send(userAvatarUrl)
這篇關于如何在 discord.py 中獲取帶有 id 的用戶頭像?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!