How can I make my bot use my custom emoji in any discord server?
@bot.command(pass_context=True)
async def ping(ctx):
msg = "Pong :CustomEmoji: {0.author.mention}".format(ctx.message)
await bot.say(msg)
Example: If I upload some custom emojis on Server 1 and when we use the !ping
command (mentioned above) in Server 2 or Server 3 or any server where the bot has access to, it should use the custom emoji.
Result: Pong with:CustomEmoji:
From https://github.com/Rapptz/discord.py/issues/390 :
It's
<:emoji_name:emoji_id>
for custom emojis.You can also find the discord.Emoji instance through Server.emojis and then cast it to str.
同样对于动画的你做<a:emoji_name:emoji_id>
As we know, every discord bot has nitro privileges when it comes to using emotes. So a bot can access any emoji for all servers it has been added to. What I do is make an API converter for myself with a global emote dictionary.
emojis=None
@bot.command(pass_context=True)
async def ping(ctx):
global emojis
if not emojis:
emojis = {e.name:str(e) for e in ctx.bot.emojis}
msg = "Pong :CustomEmoji: {0.author.mention}".format(ctx.message).replace(':CustomEmoji:',emojis['CustomEmoji'])
await ctx.send(msg)
@bot.event
async def on_reaction_add(reaction, user):
if reaction.emoji.id == emoji_id:
await reaction.message.delete()
IMPORTANT: Change the emoji_id, It deletes the message
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.