Ошибка None-Type is not subscritable. Discord.py
@tasks.loop(seconds = 60.0)
async def voiceupdate(self):
try:
channels = []
user_data = self.collection.find_one({"id": ['id']})
category = self.client.get_channel(797054633691709485)
for channels in category.channels:
if isinstance(channels, discord.VoiceChannel):
if len(channels.members) != 0:
self.collection.update_one({"id": ['id']}, {"$inc": {'minvoice': 1}})
if user_data['minvoice'] < 60 and user_data['minvoice'] >= 60:
hours = user_data['minvoice'] // 60
minutes = user_data['minvoice'] % 60
self.collection.update_one({"id": ['id']}, {"$set": {"hoursvoice": hours, "minvoice": minutes}})
except Exception:
traceback.print_exc()
И так вот мой некий цикл, который должен каждые 60 секунд проверять людей в канале Discord. (discord.py), вопрос в том правильно ли я все сделал? У меня при заходе в один канал пользователю создается его личный. Для этого сделал массив channels. Правильно ли я проверяю людей в канале а каналы в категории?
Ошибка:
File "c:\UsersДанил\Desktop\dsbot\testpy\cogs\voice.py", line 32, in voiceupdate
if user_data['minvoice'] >= 60:
TypeError: 'NoneType' object is not subscriptable
Также есть еще одна у меня система, это система мута
@commands.Cog.listener()
async def on_message(self, message):
mute_data = self.collection.find_one({"id": message.author.id})
badwords = [word for word in self.matwords if word in message.content.lower()]
if len(badwords) != 0:
embed = discord.Embed(description = f"Уважаемый {message.author.mention}, ругаться некультурно, так что вы получаете наказание.", color = 0x2f3136)
embed.set_author(name = "Администратор:", icon_url = "https://cdn.discordapp.com/emojis/818391566765916171.png?v=1")
mes = await message.channel.send(embed = embed)
await message.author.add_roles(message.guild.get_role(811882960374202389))
await asyncio.sleep(5)
await message.delete()
await mes.delete()
self.collection.update_one({"id": message.author.id}, {"$set": {"mute": True, "mutesum": 1, "mutetime": 300}})
if mute_data['mutesum'] >= 0 and mute_data['mutesum'] <=7:
embed = discord.Embed(description = f"Уважаемый {message.author.mention}, вам выдано предупреждение за большое количество полученных мутов.", color = 0x2f3136)
embed.set_author(name = "Администратор:", icon_url = "https://cdn.discordapp.com/emojis/818391566765916171.png?v=1")
await message.author.send(embed = embed)
self.collection.update_one({"id": message.author.id}, {"$inc": {"warn": 1, "warntime": 48}})
if mute_data["warn"] >= 3:
await message.author.ban(reason = "Превышено количество предупреждений.")
embed = discord.Embed(description = f"Пользователь {message.author.mention}, был забанен по причине:\n**{message.author.reason}**.")
embed.set_author(name = "Администратор:", icon_url = "https://cdn.discordapp.com/emojis/818391566765916171.png?v=1")
channelbans = self.client.get_channel(823231082728128543)
await channelbans.send(embed = embed)
Ошибка в if mute_data['mutesum'] >= 0 and mute_data['mutesum'] <=7: Оно игнорит это проверку, а после еще и такая ошибка
File "C:\Users\Данил\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\Данил\Desktop\dsbot\testpy\cogs\admin.py", line 36, in on_message
await message.author.send(embed = embed)
Ответы (1 шт):
File "c:\UsersДанил\Desktop\dsbot\testpy\cogs\voice.py", line 32, in voiceupdate if user_data['minvoice'] >= 60: TypeError: 'NoneType' object is not subscriptable
Такое поведение системы вызвано тем, что вы пытаетесь по индексу обратиться к None Объекту.
>>> user_data = None
>>> user_data[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable
Ошибка в if mute_data['mutesum'] >= 0 and mute_data['mutesum'] <=7: Оно игнорит это проверку, а после еще и такая ошибка
Врядли оно игнорит, скорее у вас ваше условие не отрабатывает.
Принтите всё, проверйте.