python - 我正在尝试在 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'
解决方案
client.send_message()
已被弃用。
它被替换为:
await ctx.message.channel.send('message')
或者您可以将其缩短为
await ctx.send('message')
另外,请不要将您的机器人令牌透露给互联网。我敦促您尽快刷新您的令牌。
推荐阅读
- mongodb - 如何将数据附加到 MERN 堆栈中 mongodb 中的现有数组
- javascript - 如何在画布上垂直居中对齐多行文本(在 NodeJS 中)
- nlp - 如何解决nlp情感分析的难句
- python - Python pandas 从数据框中获取值并存储在对象中
- python - 使用 layout_manager 网格动态调整带有滚动条的画布大小
- reactjs - 如何从 reactjs customhook 中获取价值?
- npm - 为什么找不到全局安装的 npm 包?
- python - Apache Airflow - BigQuery 运算符问题
- javascript - 单击时打开和关闭 div
- deep-learning - 多层感知器第一层权重