本文介紹了在 discord.py 中訪問成員的橫幅的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在制作圖像配置文件命令.我想為此訪問會(huì)員的橫幅.有什么方法可以在 discord.py 中做到這一點(diǎn)?
I am making an image profile command. I would like to access the member's banner for this. Is there any way we can do that in discord.py?
如果不清楚我所說的橫幅是什么意思,那么帶有藍(lán)色背景的圖像就是橫幅.我想訪問它.
If it is not clear what i mean by banner then, the image with the blue background is the banner. I would like to access that.
推薦答案
discord.py v2.0可以使用
In discord.py v2.0 you can use
# You may have to re-fetch the user for the banner to work properly
user = await bot.fetch_user(user.id)
banner_url = user.banner.url # The URL of the banner
在v2.0之前,有一種hacky方式可以直接使用API??獲取banner
Before v2.0, there is a hacky way to get the banner by directly using the API
req = await bot.http.request(discord.http.Route("GET", "/users/{uid}", uid=user.id))
banner_id = req["banner"]
if banner_id:
banner_url = f"https://cdn.discordapp.com/banners/{user.id}/{banner_id}?size=1024"
else:
# The user doesn't have a banner, do what you want
# In many forks, User.accent_color exists so you
# may want to check if your library supports that first
pass
要安裝 discord.py v2.0,您應(yīng)該運(yùn)行
To install discord.py v2.0 you should run
pip install -U git+https://github.com/Rapptz/discord.py
這篇關(guān)于在 discord.py 中訪問成員的橫幅的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!