問題描述
我有一個關于不和諧的簡單問題.我正在嘗試創建一個經濟系統,它運行良好,但我想對其進行一些定制.我正在使用這個人的模塊:https://github.com/Rapptz/discord.py
I have a simple questions about discord. I am trying to create an economy system, and it works well, but I want to customize it a bit. I am using this person's module: https://github.com/Rapptz/discord.py
如何將用戶名轉換為不和諧的 ID.例如,如果我有一個不和諧的命令"允許人們互相贈送金錢,例如:james#0243
types !give 100 bob#9413
.
How do I convert a username to a discord ID. For example if I have a discord "command" to allow people to gift each other money, like: james#0243
types !give 100 bob#9413
.
如何將 bob#9413
轉換為像 58492482649273613
這樣的不和諧 ID,因為在我的數據庫中,我將人們的用戶存儲為他們的 ID,而不是他們作為人的實際用戶名可以更改他們的用戶名.
How can I convert bob#9413
to a discord id like 58492482649273613
because in my database, I have people's users stored as their ID rather than their actual username as people can change their username.
推薦答案
使用 converter 獲取目標的Member
對象,其中將包含他們的id
.
Use a converter to get the Member
object of the target, which will include their id
.
from discord import Member
from dicord.ext.commands import Bot
bot = Bot(command_prefix='!')
@bot.command()
async def getids(ctx, member: Member):
await ctx.send(f"Your id is {ctx.author.id}")
await ctx.send(f"{member.mention}'s id is {member.id}")
bot.run("token")
轉換器非常靈活,因此您可以提供姓名、昵稱、ID 或提及.
Converters are pretty flexible, so you can give names, nicknames, ids, or mentions.
這篇關于如何將用戶名轉換為不和諧的 ID?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!