discord.py emoji all servers bot in - python

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.
using:
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?

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).
You can get rid of get finding by name and just use bot.get_emoji() where bot is your bot/client object.
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.
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.
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).
You can quickly get emoji ID by using Discord client app:
enter custom emoji in the text box input
enter \ before emoji
send message to chat
message will transfom into somemthing like <:emoji_name:emoji_id>

Yes, this is necroposting, but this may help for anyone looking for the answer.
#client.command()
async def emoji(ctx, emojiname):
for i in client.guilds:
emoji = discord.utils.get(i.emojis, name=emojiname)
Of course you have to pass the emoji's name as the first argument.

Related

Discord.py - Ban by reading a list with discord names

I want to create a discord bot in python that bans a member , if its name is listed on a provided list of a private channel on the same server.
For example, in my server there is a channel that only I can see that has listed names+discord IDs.
I want to make a bot that if a user joins the server and his name is on that list, to get auto-banned.
something like:
if username==Read_ListItems then
ban User
end if
Simple as that, but I'm not familiar with discord commands at all.

Get all guilds' id for registering slash commands

I'm developing a discord bot and I want to add slash commands to it. So I didn't found anyway to add all guild ids to a list or sth else. Could you please help me find a way to do that? (discord.py)
It's hard to understand what you are asking for.
There is a method to get the bot guilds
using bot.guilds.
In order to send a message to all guilds:
for guild in bot.guilds:
await guild.text_channels[0].send(<message>)
Quoted from AlexINF

Discord bot animated emoji unable to fetch and use as reaction

I am trying to fetch an animated emoji from server that my bot is not in, however I able to send that emoji to my server through it's link and via await.. But when I try to fetch it using "get_emoji()" method, and use it as a reaction, It shows an error : Unknown Emoji.
Following is the code:
if message.channel.id == 852947148310839303:
emoji=bot.get_emoji("https://cdn.discordapp.com/emojis/819465471786221570.gif?v=1")
await message.add_reaction(f"{emoji}")
return
I have also tried by pasting emoji's ID by <a:emoji_name:emoji_id>, but in both cases url and emoji code, the error I am getting is same : Unknown Emoji.
What am I doing wrong? and is there any other way of fetching animated emojis and use it as reactions?
You can't use emojis from servers that the bot is not in.
The parameter for the get_emoji method is supposed to be the emoji ID you're trying to get, not what it's supposed to look like/its emoji link.
So instead of
bot.get_emoji("https://cdn.discordapp.com/emojis/819465471786221570.gif?v=1")
it's
bot.get_emoji(819465471786221570)
Have a great day!

discord.py listen for and send private message

I am trying to make a discord bot in Python that listens for private messages and then replies.
The way I want it to be designed is that the user sends a command to the bot "!token", the bot then iterates over an Array. And if the discordID of the message sender is in the list, the bot then returns a token related to that discordID. If the discordID is not there then it replies with "No token".
Quite new to Python. I have looked through documentations and cant seem to find what I am looking for.
Thanks in advance!
As you said that you're new to discord.py and Python in general I've written out a bit more than I generally would without an example of what you've tried yourself.
The way this is set up now it'll only listen to "!token" You can take this code and add your own commands to it by following the same schematic. I've also left the part where you store the tokens out because you weren't clear on how you wanted that. I'd read up on python dictionaries to store those though.
As Patrick Haughs mentioned you can use the check commands.dm_only to make sure this will only run in private messages and not in any servers your bot might connect to.
from discord.ext import commands
idList =[IDS]
bot = commands.Bot(command_prefix = "!")
runtoken = TOKEN
#bot.command()
async def token(ctx):
if ctx.author.id in idList:
await ctx.author.send("Token")
else:
await ctx.author.send("No token")
bot.run(runtoken)

Cannot "send_message" in Telegram Bot API

In my own library I'm trying to send a message using "sendMessage" API method from Telegram Bot API. I've create a channel titled, say, "my_channel123" and my user name is "my_username123". So I'm an admin of the channel and the only user.
When I'm trying to send a message to the whole channel or myself from a bot, I get an error Bad request 400. Here's how I'm trying to do that:
my_bot.send_message(chat_id="#my_channel123", text="tetfdsfd")
# or
my_bot.send_message(chat_id="#my_channel123my_username123", text= "tetfdsfd")
# or
my_bot.send_message(chat_id="#my_username123", text="tetfdsfd")
I believe the error is somewhere in the format of the ids of the channel or user name or both. Are all these 3 calls correct, meaning is the format I use for chat_id correct?
Note that most likely the probable case is the id of the chat or user_name (or rather, the format) or something else because other post and get methods in my library work properly.
You have to add the bot to be an administrator of the channel before it can send messages to the channel. After you do that, your first line should work:
my_bot.send_message(chat_id="#my_channel123", text="tetfdsfd")
Also remember that whatever follows the # should be the channel username, not the title.
when sending a message to a channel, i think its easiest to send it with the channel id...
there are a few ways to get the channel id
if the bot is a admin in the channel (go to "add admin..." and search for your bot to add it), then any message sent in the channel, the bot would be able to see it, and in every message there is an id of the sender, if its in a channel, its the channel id...
use this bot #ChannelIdBot... though the bot will still need to be in the channel as an admin, in order to send messages...

Categories

Resources