【发布时间】:2021-04-14 06:51:50
【问题描述】:
该函数会检查有反应的频道是否是机器人和用户之间的私人频道,然后做其他事情。
代码:
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
emoji = payload.emoji
author = payload.member
if emoji.is_custom_emoji():
emoji_count = discord.utils.get(msg.reactions, emoji=emoji).count
else:
emoji_count = discord.utils.get(msg.reactions, emoji = emoji.name).count
cur.execute(f"SELECT discord_user_dmchannel_id FROM users WHERE discord_user_id = \
{int(payload.user_id)};")
print(cur.fetchone())
channel_dm_id_list = list(cur.fetchone())
channel_dm_id = channel_dm_id_list[0]
if payload.channel_id == channel_dm_id:
if int(emoji_count) > 1:
if emoji = ...
输出:
(782664385889959976,)
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\plays\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py",
line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\plays\OneDrive\Рабочий стол\Python\bot2.py", line 130, in on_raw_reaction_add
channel_dm_id_list = list(cur.fetchone())
TypeError: 'NoneType' object is not iterable
表格列:
users(
discord_user_id INT PRIMARY KEY,
discord_user_dmchannel_id INT,
discord_user_name TEXT,
...
...);
【问题讨论】:
-
如果没有结果,
fetchone是否返回None?