discord.py emoji 所有服务器机器人 [英] discord.py emoji all servers bot in

查看:33
本文介绍了discord.py emoji 所有服务器机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个机器人,它发送包含特定于每个嵌入的表情符号的嵌入,它在我上传表情符号的测试服务器上运行良好,但它们不会显示在其他服务器上,因为这些服务器没有自定义表情符号.

I have a bot that sends embeds that include emojis specific to each embed and it works great on my test server where I uploaded the emojis but they don't show up on other servers since those servers don't have the custom emoji.

使用:

emoji = get(ctx.message.guild.emojis, name='emojinamehere')

当然适用于它所在的服务器,但有没有办法从机器人所在的任何服务器获取和使用所有表情符号?

works of course for the server it's in but is there a way to get and use all emojis from any servers the bot is in?

推荐答案

因为您专门使用 ctx.message.guild.emojis aka 您正试图从上下文行会获取表情符号(可能没有).

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 按名称查找,只需使用 bot.get_emoji() 其中 bot 是您的 bot/client 对象.

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 客户端快速获取 emoji ID:

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

  • 在文本框输入中输入自定义表情符号
  • 在表情符号前输入
  • 发送消息聊天
  • 消息会变成类似 <:emoji_name:emoji_id>
  • 的东西

这篇关于discord.py emoji 所有服务器机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆