My bot uses custom emojis in embed.
guild, where its own custom emoji is working, but custom emojis are not working in other guilds.
code:
exp = Exp(check[i],check[i-1]*30*int(check[i-1]/15+1))
guild= client.get_guild(955246008923742209)
block_id=["0_","1_","2_","3_","4_","5_","6_","7_","8_","9_","10","9_5"]
block_list=[discord.utils.get(guild.emojis,name=i) for i in block_id]
await interaction.response.send_message(content=exp.block(block_list))
exp.block:
def block(self,list:list):
string=""
cnt=1
for _ in range(int(self.percent()/10)):
cnt+=1
string+=str(list[10])
if float(self.percent())%10 >=9.5:
string+=str(list[11])
else:
string+=str(list[int(self.percent())%10])
while cnt<10:
cnt+=1
string+=str(list[0])
print(string)
return string
output:
<:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:10:1006826883607953459><:3_:1006839879759568976><:0_:1006839873216450570>
but chat in not own emoji guild :
:10::10::10::10::10::10::10::10::3_::0_:
what should I do?
Related
So I got this script, and it doesn't work but does not write any errors in console. Just doesn't send message at all.
async def run(ctx,channel,arg1,arg2,arg3):
color = arg3
if color in color_table:
actual_color = getattr(discord.Colour, color)()
embed=discord.Embed(title=arg1, description=arg2, color=actual_color)
embed.set_footer(text="Powered by T.A.D.S.")
channel_id = channel.id
channel = discord.utils.get(ctx.guild.text_channels, id=int(channel_id))
await channel.send(embed=embed)
else:
await ctx.channel.send("This color doesn't exist in discord databeses. Type !colours to show all colors that are available.")
I want the bot to send a message to specified channel but it does nothing.
I recently started to learn discord.py and I wanted to add a welcome message for multi-channels and I found this post Discord.py welcome message for multiple servers I tried the code and seems to be working without any errors but I'm facing a problem creating a welcome message with this code because I don't have experience with discord.py I will have the code listed below and at the very bottom I will have the welcome code I tried if somebody can help it would be great
Thank you
#client.event
async def on_guild_join(guild):
#loads json file to dictionary
with open("welcome-message.json", "r") as f:
guildInfo = json.load(f)
guildInfo[guild.id] = guild.text_channels[0] #sets key to guilds id and value to top textchannel
#writes dictionary to json file
with open("welcome-message.json", "w") as f:
json.dump(guildInfo, f)
#allows server members to set channel for welcome messages to send to
#client.command()
async def welcomeMessage(ctx):
with open("welcome-message.json", "r") as f:
guildInfo = json.load(f)
guildInfo[ctx.message.guild.id] = ctx.message.channel.id #sets channel to send message to as the channel the command was sent to
with open("welcome-message.json", "w") as f:
json.dump(guildInfo, f)
# welcome code
#client.event
async def on_member_join(ctx, message):
with open("welcome-message.json", "r")as f:
guildInfo = json.load(f)
channel = guildInfo[ctx.message.guild.id]
embed = discord.Embed(title="Welcome ""!",
description=f"We're so glad you're here !", color=discord.Color.green())
await channel.send(embed=embed) ```
You have to specify the member intent to receive on_member_join events. You can do this while creating your bot object by adding an intent option:
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents=intents, other_options)
Note
If your bot is verified you require the SERVER MEMBERS INTENT which you can request on the bot page of your application.
Also:
On this line here:
embed = discord.Embed(title="Welcome ""!", it will error out as there are quotes in a quoted string, if you want to keep those quotes switch the quotes to single quotes (')
If we have a message with ⬇️ and ⬆️ Reaction.
How can we get all users reacted in particular emojis and how to use as button.
Like,
If a user reacts his name will be added in message along with the emoji which he reached.
Here is a simple example this is not the best method since this will be active on all bot messages when someone reacts with ⬆️. The best is save the message id that you want then do a check here to make sure it is the wanted message.
If message.id is not an option then make a dedicated channel for this and hard code the id of that channel, this is not the best practice but it will work.
#bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
message = channel.get_message(payload.message_id)
# guild = bot.get_guild(payload.guild_id)
emoji = payload.emoji.name
# skip DM messages
if isinstance(channel, discord.DMChannel):
return
# only work if in bot is the author
# skip messages not by bot
# skip reactions by the bot
if message.author.id != bot.user.id or payload.member.id == bot.user.id:
return
if emoji == '⬆️':
up_users = f"{message.content} \n {user.name}"
await message.edit(up_users)
# remove user reaction
reaction = discord.utils.get(message.reactions, emoji=emoji)
await reaction.remove(payload.member)
I am making a reaction role system, but when I react with the emoji I put, it does nothing. The code is here:
#bot.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 757982178691776635:
guild_id = payload.guild_id
guild = bot.get_guild(guild_id)
if payload.emoji.name == 'white_check_mark':
print('Role')
I get no error in console and it does not print Role in console.
Try printing the value of payload.emoji.name, it is going to be the emoji itself usually. If you want to match based on the unicode name, I suggest using unicodedata.name
You can get the emoji charcter from here and then compare it.
I made it a little bit shorter for ease of read.
#bot.event
async def on_raw_reaction_add(payload):
if payload.message_id == 757982178691776635:
guild = bot.get_guild(payload.guild_id)
if payload.emoji.name == '✅':
print('Role')
Discord.py, how to set a command, without Prefix, only with certain word to which bot replies, and also bot replies to that command while Dm with the bot.
Remember about the errors for example, bot object has no attribute on_message, etc, errors.
You can write a function to pass to command_prefix that will check for one prefix in servers and another (or none) in private messages:
from discord.ext import commands
def command_prefix(bot, message):
if message.guild is None:
return ''
else:
return '$'
bot = commands.Bot(command_prefix=command_prefix)
#bot.command(name='hello')
async def hello(ctx):
await ctx.send("Hello")
bot.run("TOKEN")
If you are using this in a cog.
#commands.Cog.listener()
async def on_message(self,message):
await message.send("Hello!")
or in the main.py
#bot.event
async def on_message(message):
await message.send("Hello!")
Please reply back if you have an error with this.
message.guild will return None if the message is in dms.