【问题标题】:Discord.py Reaction autorole Error : Instance of 'reactions' has no 'reaction_message' memberDiscord.py Reaction autorole 错误:“reactions”实例没有“reaction_message”成员
【发布时间】:2021-02-20 02:44:49
【问题描述】:

所以我正在尝试为我的学校制作一个机器人,目标是在全校范围内创建一个机器人,它可以自动将学生分配到他们的角色,以便他们可以访问他们班级的特定频道。在整个学校有一种交流方式会很酷。 所以我从 YouTube 上挑选了一个很酷的教程 如果你想的话,这里是链接:https://www.youtube.com/watch?v=WQsQERxtD2w&list=PLYeOw6sTSy6ZGyygcbta7GcpI8a5-Cooc&index=29&t=1177s&ab_channel=CarberraTutorials 它似乎很完美,所以我做到了:

1 from discord.ext.commands import Cog
2 from discord.ext import commands
3
4 client  = commands.Bot(command_prefix='!')
5
6class reactions(Cog):
7  def __init__(self, bot):
8     self.bot = bot 
9@Cog.listener()
10async def on_ready(self):
11        if not self.bot.ready:
12            self.filière = { # In French "filière" means a course of study that you take in high school
  13              "????" : (809130298452869126), #Proffesioenl 
   14             "????‍????" : (809130233835683901), # thecnologique 
   15             "????‍????" : (809130260678311997), # generale
    16        }
    17        **self.reaction.message** = await self.bot.get_channel(809123408720822284).fetch_message(812283647490392104)
    18        self.bot.cogs_ready.ready_up("reactions")
19
20@Cog.listener()
21 async def on_raw_reaction_add(self, payload):
22    if self.bot.ready and payload.message_id == **self.reaction_message.id:**
23        print(payload.emoji.name)
24        role = self.bot.guild.get_role(self.filière[payload.emoji.name])
25        await payload.member.add.roles(role, reason="Choix de la filière")
26
27@Cog.listener()
28async def on_raw_reaction_remove(self, payload):
29    if self.bot.ready and payload.message_id == **self.reaction_message.id:**
30        member = self.bot.guild.get_member(payload.user_id)
31        await member.remove_roles(self.filière[payload.emoji.name], reason="Choix de la filière")

现在我遇到了一个问题,这是我得到的 3 个错误:(我添加了显示问题所在的行,我还添加了一个粗体字体,Visual Studio Code 显示错误是)

  • “反应”实例没有“反应”成员行 17
  • “reactions”实例没有“reaction_message”成员行 22
  • “reactions”实例没有“reaction_message”成员行 29

因此,如果您有解决方案,将受到欢迎

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    self.reaction.message 第 17 行应该是 self.reaction_message,也许吧?

    【讨论】:

      猜你喜欢
      • 2021-04-20
      • 1970-01-01
      • 2020-05-05
      • 2019-05-27
      • 2021-03-14
      • 2020-12-04
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      相关资源
      最近更新 更多