AttributeError:“ LevelingSystem”对象没有属性“ author”

称为

我正在制作一个不和谐的机器人,目前正在开发一个调平系统。但是我一直在收到AttributeError:'LevelingSystem'对象没有属性'author'

这是它的代码

import discord
from discord.ext import commands
from discord.utils import get
import json
import random
import time


class LevelingSystem(commands.Cog):
    """ Leveling system for discord """

    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(message, guild):

        if message.author.bot:
            return
        else:
            with open("X:\\Code\\Projects\\Python\\AlphaWolf\\cogs\\levels.json", 'r') as f:
                levels = json.load(f)

            await update_data(levels, message.author.id)

        async def update_data(levels, user):
            for member in guild.members:
                if user not in levels:
                    levels[user] = {}
                    levels[user]["experience"] = 0
                    levels[user]["level"] = 1
                    print(" Registered {} to .json".format(user))
                    with open("X:\\Code\\Projects\\Python\\AlphaWolf\\cogs\\levels.json", 'w') as f:
                        json.dump(levels, f)

def setup(bot):
    bot.add_cog(LevelingSystem(bot))
迪格

您正在使用嵌齿轮,并且由于您的事件在类中,因此需要self在类方法中将关键字作为第一个arg包含在内

class LevelingSystem(commands.Cog):
    """ Leveling system for discord """

    def __init__(self, bot): # self is used here
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, message, guild): # need it here as well
        # rest of the code

假设self关键字被调用message是因为它始终是类方法中的第一个参数。
因此,当您说的时候message.author,该程序实际上是在假设author您的类中有一个称为的属性-它看起来message.author像是self.author

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

AttributeError:“元组”对象没有属性“ set_author” discord.py

来自分类Dev

AttributeError:对象没有属性

来自分类Dev

AttributeError: '' 对象没有属性 ''

来自分类Dev

AttributeError:“列表”对象没有属性“对象”

来自分类Dev

AttributeError:“模块”对象没有属性“ tk”

来自分类Dev

AttributeError:'NoneType'对象没有属性'ravel'

来自分类常见问题

AttributeError:“模块”对象没有属性“测试”

来自分类Dev

AttributeError:“模块”对象没有属性“缓存”

来自分类Dev

AttributeError:'dict'对象没有属性'predictors'

来自分类Dev

AttributeError:“模块”对象没有属性“ TestCase”

来自分类Dev

AttributeError:“模块”对象没有属性“版本”

来自分类Dev

AttributeError:对象没有属性“ tk”

来自分类Dev

AttributeError:“模块”对象没有属性

来自分类Dev

AttributeError:“ float”对象没有属性“ center”

来自分类Dev

“ AttributeError:'list'对象没有属性'ravel'”

来自分类Dev

AttributeError:“模块”对象没有属性“绘图”

来自分类Dev

AttributeError:“ Response”对象没有属性“ json”

来自分类Dev

AttributeError:'NoneType'对象没有属性'endswith'

来自分类常见问题

AttributeError:“模块”对象没有属性“请求”

来自分类常见问题

AttributeError:“ ChooseBook”对象没有属性“ txtrd”

来自分类Dev

AttributeError:'Figure'对象没有属性'plot'

来自分类Dev

AttributeError:“模块”对象没有属性“ SignedJwtAssertionCredentials”

来自分类Dev

AttributeError:“ DataFrame”对象没有属性

来自分类Dev

AttributeError:“会话”对象没有属性“保存”

来自分类Dev

AttributeError:“模块”对象没有属性

来自分类Dev

AttributeError:“模块”对象没有属性“ SFrame”

来自分类Dev

AttributeError:“模块”对象没有属性“ scandir”

来自分类Dev

Tkinter AttributeError:对象没有属性“ tk”

来自分类Dev

AttributeError:“ FreqDist”对象没有属性“ inc”

Related 相关文章

  1. 1

    AttributeError:“元组”对象没有属性“ set_author” discord.py

  2. 2

    AttributeError:对象没有属性

  3. 3

    AttributeError: '' 对象没有属性 ''

  4. 4

    AttributeError:“列表”对象没有属性“对象”

  5. 5

    AttributeError:“模块”对象没有属性“ tk”

  6. 6

    AttributeError:'NoneType'对象没有属性'ravel'

  7. 7

    AttributeError:“模块”对象没有属性“测试”

  8. 8

    AttributeError:“模块”对象没有属性“缓存”

  9. 9

    AttributeError:'dict'对象没有属性'predictors'

  10. 10

    AttributeError:“模块”对象没有属性“ TestCase”

  11. 11

    AttributeError:“模块”对象没有属性“版本”

  12. 12

    AttributeError:对象没有属性“ tk”

  13. 13

    AttributeError:“模块”对象没有属性

  14. 14

    AttributeError:“ float”对象没有属性“ center”

  15. 15

    “ AttributeError:'list'对象没有属性'ravel'”

  16. 16

    AttributeError:“模块”对象没有属性“绘图”

  17. 17

    AttributeError:“ Response”对象没有属性“ json”

  18. 18

    AttributeError:'NoneType'对象没有属性'endswith'

  19. 19

    AttributeError:“模块”对象没有属性“请求”

  20. 20

    AttributeError:“ ChooseBook”对象没有属性“ txtrd”

  21. 21

    AttributeError:'Figure'对象没有属性'plot'

  22. 22

    AttributeError:“模块”对象没有属性“ SignedJwtAssertionCredentials”

  23. 23

    AttributeError:“ DataFrame”对象没有属性

  24. 24

    AttributeError:“会话”对象没有属性“保存”

  25. 25

    AttributeError:“模块”对象没有属性

  26. 26

    AttributeError:“模块”对象没有属性“ SFrame”

  27. 27

    AttributeError:“模块”对象没有属性“ scandir”

  28. 28

    Tkinter AttributeError:对象没有属性“ tk”

  29. 29

    AttributeError:“ FreqDist”对象没有属性“ inc”

热门标签

归档