【发布时间】:2019-10-31 21:58:29
【问题描述】:
我已经在不和谐机器人上玩了很长时间了,今天我遇到了这个错误。我想看看有没有人能帮我解决这个问题。
错误将发布在底部以及我正在运行的事件。
我正在为我的不和谐服务器制作票务系统,我发现如果不使用On_Raw_Reaction_Add 事件我无法做到这一点。有效载荷对我来说似乎很困惑,但我几乎可以正常工作。最后剩下的就是公会了。出于某种原因,当使用下面的片段引用/拉动公会时,在不和谐导入的 guild.py 中,它说公会被认为是 NoneType 但如果我从事件中打印它,它就可以正常工作。我只想创建一个频道。
截图
guild = self.client.get_guild(reactionpayload.guild_id)
@commands.Cog.listener()
async def on_raw_reaction_add(self, reactionpayload):
print('ran')
db = sqlite3.connect(DATA_FILENAME)
cursor = db.cursor()
cursor.execute(f"SELECT ID FROM Ticket_Channel")
channelID = cursor.fetchone()[0]
cursor.close()
channel = self.client.get_channel(int(channelID))
if channel is None:
print('Ticket System: Channel not Found!')
else:
if reactionpayload.message_id == channel.last_message_id:
if not self.client.get_user(reactionpayload.user_id).bot:
guild = self.client.get_guild(reactionpayload.guild_id)
print(guild.id)
name = 'ticket-' + str(self.client.get_user(reactionpayload.user_id).name)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
guild.me: discord.PermissionOverwrite(read_messages=True),
guild.get_member(self.client.get_user(reactionpayload.user_id)): discord.PermissionOverwrite(read_messages=True)
}
channel = await guild.create_text_channel(name, overwrites=overwrites, category=self.client.get_channel(self.client.get_channel(reactionpayload.channel_id).category_id), position=100)
await remove_reaction('\U0001F4E9', self.client.get_user(reactionpayload.user_id))
else:
print(reactionpayload.message_id)
print(channel.last_message_id)
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\gunzb\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 270, in _run_event
await coro(*args, **kwargs)
File "C:\Users\gunzb\Desktop\AkumaBot\cogs\ticket_system.py", line 41, in on_raw_reaction_add
channel = await guild.create_text_channel(name, overwrites=overwrites, category=self.client.get_channel(self.client.get_channel(reactionpayload.channel_id).category_id), position=100)
File "C:\Users\gunzb\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\guild.py", line 882, in create_text_channel
data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
File "C:\Users\gunzb\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\guild.py", line 785, in _create_channel
'id': target.id
AttributeError: 'NoneType' object has no attribute 'id'
【问题讨论】:
标签: python discord discord.py-rewrite