Making my Discord.py bot send an animated emoji - animation

I have attempted this as my code.
#client.command()
async def party(ctx):
party = client.get_emoji(786138532069900350)
await ctx.send('{}'.format(party))
but it replies as None
It's an animated default discord emoji Emoji
So what am I doing wrong?

To send an animated emoji you should find the emoji name and the emoji id..
To send a normal emoji we use this format:
<:emojiname:emojiid>
To send an animated one we use:
<a:emojiname:emojiid>
After that you need to edit your code as follows..
#client.command()
async def party(ctx):
party = "<a:youremojiname:emojiid>" #assigning the emoji
await ctx.send(party) #sending the emoji

Or if none of these methods work, simply send it like:
await ctx.send("https://cdn.discordapp.com/emojis/836234327016210482.gif?v=1")

With a some research I found https://github.com/Rapptz/discord.py/issues/390:
Basically what it includes to use custom emojis
To use a custom emoji, you use the emoji name, then it's id which can be
extracted from the middle id from its link id.
For example, the id of this emoji is:
Original link: https://cdn.discordapp.com/emojis/3489241209391.png?v=1
Emoji id: 3489241209391
In the example shown below, it would appear as the emoji when sent in a message
<:emoji_name:emoji_id>
example: <:myemoji:3489241209391>
With an animated emoji is the same, but append an "a" at the front
<a:emoji_name:emoji_id>

I have noticed that your get_emoji variable name is party, the same as command (or function's) name, That's why it is returning None. Please change the variable name to something other then function's name.
Example:
#client.command()
async def party(ctx):
partyemoji = client.get_emoji(786138532069900350) # problem was here
await ctx.send(partyemoji) # instead of formatting string simply use variable name.
P.S: If it still returns None check if your emoji ID is valid or not.

Related

Is it possible to change the color of the name of a discord.py bot in code?

I have been searching and can't seem to find a way to change the color of the discord bots itself name within the code. Like if I have a bot name Color Bot and someone calls !function1 I can have the bot have a red name but if they call !function2 the bot will have a blue name.
In discord, the color depends on the color of the highest role the bot has. We will just have to change the color of the bot's role to change its color.
#bot.command()
async def change_color(ctx, color: discord.Colour):
role = ctx.guild.self_role
if role is None:
return await ctx.send('i dont have a default role')
await role.edit(colour=color)
await ctx.send('changed my color')
Note: This will only work if your bot has permissions to edit this role, it needs to have a higher no color role to edit this role.
References:-
self_role
Colour
Role.edit

Scrolling down in a discord.py embed

This is my embed rn
It uses the google API to get upcoming events on a calendar but I have to limit the number of events it gets since the message will be too long. The list of calendars is stored in the description of the embed. Is there any way to limit the embed to a certain size and be able to scroll down in the description so all events can be displayed?
As Zimano said, you can't have scrollable elements in embeds, but what you can do is a multi-page embed, the easiest approach would be with ext.menus (To install it: python -m pip install -U git+https://github.com/Rapptz/discord-ext-menus)
import discord
from discord.ext import menus
class MultiPageEmbed(menus.ListPageSource):
async def format_page(self, menu, entry):
return entry
#bot.command()
async def whatever(ctx):
# Put all your embeds here
embeds = [discord.Embed(title="Embed 1"), discord.Embed(title="Embed 2"), discord.Embed(title="Embed 3")]
menu = menus.MenuPages(MultiPageEmbed(embeds, per_page=1))
await menu.start(ctx)
Unfornatelly it's still in beta so there's no docs about it.
No, you can't add scrollable elements in embeds.

How do i copy an image link when someone sends an image in chat

Im trying to figure out how to copy the link of an image the user posts. I was trying to figure out how to do this but i cant find anything that helps me, thats all im looking for.
You might be looking for this :
#client.event
async def on_message(message):
if not message.attachments:
return
attachment = message.attachments[0]
await message.channel.send(attachment.url)
Reference :
discord.Attachment
discord.Message.attachments
discord.on_message(message)

discord py - save a user posted image and delete the old one

my bot should make embeds from all messages in a specific channel. He deletes every message, that's not in an embed and puts them automatically in an embed. Now, that's working, but I have problems with the pictures that my users upload.
My question: How can I save the picture that uploaded a user in a "log-channel" and get the new discord image link from that picture?
I need the "new discord image link" to put it in the embed.
a discord.Message instance holds the attachments attribute, which will get you a list of the attachments to a message. You can then use discord.Attachment.to_file() to get a discord.File instance, which you can use in an embed.
Example:
message = SomeMessageInstance
# realistically you should be looping over the attachments, and sending an embed for each
file = await message.attachments[0].to_file()
file.filename = 'image.png'
embed = discord.Embed()
embed.set_image(url='attachment://image.png')
await Channel.send(file=file, embed=embed)

Discord.py Links in Embeds

I am looking to put an invite link to my bot in the description of the embed as a hyperlink. I want it to display something similar to click here and then lead to the bot's invite link. If anybody knows how to do this, if you could please advise me that would be great! :)
Like so: [text to click](url)
Note: This won't work in the title, footer or field titles, if you want a hyperlink in the title use the url kwarg
You can do:
async def invite(ctx):
embed = discord.Embed(
color= discord.Colour.dark_teal() # or any color you want
)
embed.add_field(name='If you wish to add me in your server,' ,value='[Click here to add]( bot link )', inline=False)
await ctx.send(embed=embed)
You can put hyperlinks in this way just in field value.

Resources