gpt4 book ai didi

python - Discord NoneType 对象 Discord 文件中出现错误?

转载 作者:行者123 更新时间:2023-12-01 00:25:08 25 4
gpt4 key购买 nike

我已经和不和谐机器人混在一起有一段时间了,今天我遇到了这个错误。我想看看是否有人可以帮我解决这个问题。

错误以及我正在运行的事件将发布在底部。

我正在为我的不和谐服务器制作一个票证系统,我发现如果不使用 On_Raw_Reaction_Add 事件,我就无法做到这一点。有效负载似乎让我感到非常困惑,但我几乎一切都可以工作。最后剩下的就是公会了。由于某种原因,当使用下面的片段引用/拉动公会时,在 guild.py 中关于不和谐导入的情况下,它说公会被认为是 NoneType 但如果我从事件中打印它,它工作得很好。我只是想创建一个 channel 。

截图

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'

最佳答案

get_member 采用 id,而不是 User 对象,因此 guild.get_member(self.client.get_user(reactionpayload.user_id))返回None

@commands.Cog.listener()
async def on_raw_reaction_add(self, reactionpayload):
if not reactionpayload.guild_id:
return # Private message
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)
member = guild.get_member(reactionpayload.user_id)
print(guild.id)
name = 'ticket-' + member.name
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
guild.me: discord.PermissionOverwrite(read_messages=True),
member: discord.PermissionOverwrite(read_messages=True)
}
channel = await guild.create_text_channel(name, overwrites=overwrites, category=channel.category, position=100)
await remove_reaction('\U0001F4E9', self.client.get_user(reactionpayload.user_id))
else:
print(reactionpayload.message_id)
print(channel.last_message_id)

关于python - Discord NoneType 对象 Discord 文件中出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58639106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com