我有一个添加自定义表情符号的Discord机器人。我希望它删除从服务器中删除时添加的所有表情符号。我正在尝试使用the API中的emoji.delete()函数,但出现此错误:
Traceback (most recent call last):
File "C:\Users\Stefon\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:/Users/Stefon/PycharmProjects/testscrape/testscrape.py", line 750, in on_guild_remove
await emoji.delete()
File "C:\Users\Stefon\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\emoji.py", line 189, in delete
await self._state.http.delete_custom_emoji(self.guild.id, self.id, reason=reason)
AttributeError: 'NoneType' object has no attribute 'id'
我的代码:
async def on_guild_remove(guild):
print('Removed from guild')
# Get all emojis in the guild
emojis = guild.emojis
# Get emoji names for all emojis added by the bot
img_names = []
for f in os.listdir('img'):
img_names.append(f.split('.')[0])
for emoji in emojis:
# Remove the first word before an underscore and check if the resulting name is in the name of images
temp_name = emoji.name.split('_')[1:]
temp_name = '_'.join(temp_name)
# If the emoji is one generated by the bot, remove it.
if temp_name in img_names:
print('Deleting emoji ' + temp_name)
await emoji.delete()
print('Done removing emojis..')
我怀疑这是因为从服务器中删除了僵尸程序后,我试图删除表情。如果是这样,我还有其他方法可以删除删除的所有表情吗?