首页 > 解决方案 > 我正在尝试在 discord py 中扮演反应角色

问题描述

我尝试运行此代码(请参阅下面的代码)。

代码:

import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="!")
@client.event
async def on_ready():
    Channel = client.get_channel('406473869424328736')
    Text= "REACT TO ME"
    Moji = await Client.send_message(Channel, Text)
    await client.add_reaction(Moji, emoji='question')
@client.event
async def on_reaction_add(reaction, user):
    Channel = client.get_channel('406473869424328736')
    if reaction.message.channel.id != Channel:
        return
    if reaction.emoji == "question":
      Role = discord.utils.get(user.server.roles, name="test")
      await client.add_roles(user, Role)
client.run("NzcxMDQxMzcwNjU5MjI1NjMw.X5mWPA.oiEvo4otmA3lThVzCBxQHunugO4")
Moji = await client.send_message(Channel, Text)

但是,我收到如下 错误:

AttributeError: 'Client' object has no attribute 'send_message'

标签: pythondiscordbots

解决方案


client.send_message()已被弃用。

它被替换为: await ctx.message.channel.send('message') 或者您可以将其缩短为 await ctx.send('message')

另外,请不要将您的机器人令牌透露给互联网。我敦促您尽快刷新您的令牌。


推荐阅读