且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

discord.py emoji表情所有服务器bot

更新时间:2023-11-30 12:11:40

因为您专门使用了 ctx.message.guild.emojis ,所以您尝试从上下文公会中获取表情符号(可能没有).

Because you're specifically using ctx.message.guild.emojis aka you're trying to get the emoji from the context guild (which might not have it).

您可以摆脱按名称查找的 get ,而只需使用机器人/客户端对象.

You can get rid of get finding by name and just use bot.get_emoji() where bot is your bot/client object.

您的机器人会将所有公会的所有表情符号存储在内部缓存中,而 get_emoji()将从那里取回它,因此它将适用于所有公会.

Your bot will store all emojis from all the guilds in internal cache and get_emoji() will retrieve it from there so it will work for all guilds.

您将需要表情符号ID(整数)来执行此操作,而不是像您当前所获得的那样命名.您可以按名称获取,然后获取其ID,但这只是不必要的步骤.

You will need emoji ID (integer) to do this, not name as you're currently getting. You could get by name and then get its ID but that's just unnecessary steps.

只需使用表情符号ID,因为它们是唯一的且不能更改(名称既可以重复也可以更改,因此您在按名称获取时会遇到麻烦).

Just use emoji ID as those are unique and can't change (names can both be duplicate and can change so you can get into problems getting by name).

您可以使用Discord客户端应用程序快速获取表情符号ID:

You can quickly get emoji ID by using Discord client app:

  • 在文本框中输入自定义表情符号
  • 在表情符号前输入 \
  • 发送消息进行聊天
  • 消息将转换为类似<:emoji_name:emoji_id>
  • 的内容