如何修复AttributeError:“非类型”对象在Discord bot代码上没有属性“get”

2024-04-23 16:45:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个功能

此功能不工作,无法打印 AttributeError:“非类型”对象没有属性“get” 如何修复

        @self.client.event
        async def on_message(message):
            if message.author == self.client.user:
                return
            if self.check_buttons.get(message.author.id, None):
                ans = None
                for i in range(len(self.check_buttons.get(message.author.id, []))):
                    if self.check_buttons[message.author.id][i].lower() == message.content.lower() or message.content.lower() == "#" + str(i + 1):
                        ans = self.check_buttons[message.author.id][i]
                        break
                if ans:
                    self.channel.send_message(message.author.id, ans)
                    self.check_buttons[message.author.id] = []
                else:
                    msg = "You entered an invalid value. Copy (Short command: # and numbers buttons):\n"
                    for i in range(len(self.btns)):
                        msg += str(i + 1) + ". " + self.btns[i] + "\n"
                    self.send_message(message.author.id, msg)
            else:
                self.channel.send_message(message.author.id,
                                          message.content)  # send event (UserID + UserMessage) to channel```

Tags: self功能sendidmessagegetifcheck
1条回答
网友
1楼 · 发布于 2024-04-23 16:45:41

if ans = self.check_buttons.get(message.author.id, None)替换为if ans = self.check_buttons.get(message.author.id) == None:

相关问题 更多 >