Discord.py 添加对自己消息的反应

Epi*_*ers 3 python discord discord.py

正如标题所示,我试图让机器人对自己的消息做出反应。这是到目前为止我的示例代码:

from inspect import CO_NESTED
from typing import Literal
from discord.ext import commands
import discord
import random
import asyncio
import time

TOKEN = "xxx"

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    username = str(message.author).split('#')[0]
    user_message = str(message.content)
    channel = str(message.channel.name)
    print(f'{username}: {user_message} ({channel})')

    if message.author == client.user:
        return
    
    if "p!react" in user_message.lower():
        await message.channel.send("hello!")
        await message.add_reaction("")


client.run(TOKEN)
Run Code Online (Sandbox Code Playgroud)

然而,这对用户的消息做出反应,而不是机器人的消息。您能提供的任何帮助将不胜感激!

abc*_*ccd 7

.send()Message返回已发送消息的新对象。您需要添加对该消息的反应。

new_msg = await message.channel.send("hello!")
await new_msg.add_reaction("")
Run Code Online (Sandbox Code Playgroud)