本文介紹了如何在 discord.py 中提及用戶?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試使用 discord.py 編寫一個簡單的機器人,所以我開始使用有趣的命令來熟悉這個庫.
I'm trying to code a simple bot using discord.py, so I started with the fun commands to get familiar with the library.
import discord
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hug'):
await message.channel.send(f"hugs {message.author.mention}")
if message.content.startswith('!best'):
user_id = "201909896357216256"
user_mention = ??? # How to convert user_id into a mention
await message.channel.send(f'{user_mention} is the best')
推薦答案
所以經(jīng)過幾天的反復(fù)試驗,我終于想出了如何做到這一點,希望其他人能從中受益,并且比我實際擁有的痛苦更少..解決方案最終很簡單..
So I finally figured out how to do this after few days of trial and error hoping others would benefit from this and have less pain than I actually had.. The solution was ultimately easy..
if message.content.startswith('!best'):
myid = '<@201909896357216256>'
await client.send_message(message.channel, ' : %s is the best ' % myid)
這篇關(guān)于如何在 discord.py 中提及用戶?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!