【问题标题】:line 13, in on_ready Moji = await client.send_message(Channel,Text) AttributeError: 'Bot' object has no attribute 'send_message'.How fix it? [duplicate]第 13 行,on_ready Moji = await client.send_message(Channel,Text) AttributeError: 'Bot' object has no attribute 'send_message'。如何解决? [复制]
【发布时间】:2021-03-20 09:53:03
【问题描述】:

(对不起我的英语)我的机器人必须通过对表情符号的反应来扮演角色,但它不起作用并且会出现这个错误:

  line 13, in on_ready
 Moji = await client.send_message(Channel,Text)
AttributeError: 'Bot' object has no attribute 'send_message'   

这是我的代码:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = ".",intents = discord.Intents.all())

@client.event
async def on_ready():
  print(discord.__version__)
  
  Channel = client.get_channel(815949348948934716)
  Text= "Выбери свою роль????"
  Moji = await client.send_message(Channel,Text)
  await client.add_reaction(Moji, emoji='????')
@client.event
async def on_reaction_add(reaction, user):
  
  Channel = client.get_channel(815949348948934716)
  if reaction.message.channel.id != Channel:
    return
  if reaction.emoji == "????":
    
    Role = discord.utils.get(user.server.roles, name="PUBG")
    await client.add_roles(user, Role)
    
client.run("My token")

请帮帮我

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

你只需要简单地做await Channel.send(Text)

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = ".",intents = discord.Intents.all())

@client.event
async def on_ready():
  print(discord.__version__)
  
  Channel = client.get_channel(815949348948934716)
  Text= "Выбери свою роль?"
  Moji = await Channel.send(Text)
  await Moji.add_reaction('?')
@client.event
async def on_reaction_add(reaction, user):
  
  Channel = client.get_channel(815949348948934716)
  if reaction.message.channel.id != Channel:
    return
  if reaction.emoji == "?":
    
    Role = discord.utils.get(user.server.roles, name="PUBG")
    await client.add_roles(user, Role)
    
client.run("My token")

【讨论】:

  • 谢谢,它会显示消息,但仍然不是很好。我收到新错误:line 13, in on_ready await client.add_reaction(Moji, emoji='?') AttributeError: 'Bot' object has no attribute 'add_reaction'
  • @HackJonny 我已经编辑了我的代码来解决这个问题。你需要做await Moji.add_reaction('?')。另外,请确保通过单击我的帖子旁边的否决按钮下方的复选按钮将我的答案标记为正确。
  • 好的,它用表情符号沙化消息,但仍然没有赋予角色,但它不会沙化错误。请帮忙??
  • 我检查了你的答案,但它不起作用。它会通过反应来沙化消息,但是当我对表情符号做出反应时,它不会发挥作用
猜你喜欢
  • 2019-05-28
  • 2021-04-06
  • 2022-12-04
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-06
  • 2022-12-01
相关资源
最近更新 更多