私はdiscord.pyを使用して単純なボットをコーディングしようとしているので、APIのコツをつかむためのような楽しいコマンドから始めました
import discord
import asyncio
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 client.send_message(message.channel, "hugs {0.author.mention}".format(message))
# Greetings
if message.content.startswith('hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
# say (id) is the best
# This is where I am lost. how to mention someone's name or id ?
if message.content.startswith('!best'):
mid = User.id('ZERO#6885').format(message)
await client.send_message(message.channel, '{mid} mentioned')
それで、他の人がこれから利益を得て、私が実際に持っていたよりも痛みが少ないことを期待して、数日間の試行錯誤の後でこれを行う方法を最終的に理解しました。解決策は最終的に簡単でした。
if message.content.startswith('!best'):
myid = '<@201909896357216256>'
await client.send_message(message.channel, ' : %s is the best ' % myid)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加