【问题标题】:discord.py add reaction to own messagediscord.py 对自己的消息添加反应
【发布时间】:2021-12-18 04:16:28
【问题描述】:

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

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)

但是,这会响应用户的消息,而不是机器人的消息。您能提供的任何帮助将不胜感激!

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

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

    new_msg = await message.channel.send("hello!")
    await new_msg.add_reaction("?")
    

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      相关资源
      最近更新 更多