Discord.py Activity (emoji)

I was working on custom activity and found in the package code a argument called: “emoji”.
What is it for?, How does it work?
I tried: :grinning:, “:smile:” I saw no changes. (Tried with the id but just got an error)

import discord
from discord import app_commands
import os
import kick.kick_log
import timee.time


intents = discord.Intents.all()
client = discord.Client(intents=intents)
guild = client.guilds
tree = app_commands.CommandTree(client)

file = kick.kick_log
tfile = timee.time
current_date = tfile.current_date



# Define your kick command
@tree.command(
    name="kick",
    description="Kicks a Target",
    guild=discord.Object(id=786934479812952085)
)
async def kick(ctx, target: discord.User, reason: str):
    # Kick logic...
  if ctx.user.guild_permissions.kick_members:
    await ctx.response.send_message(f"'Kicked' {target} for {reason} by {ctx.user} date: {current_date}. perms: {ctx.user.guild_permissions}")
    print(f"'Kicked' {target} for {reason} by {ctx.user} date: {current_date}.")
    file.log_function(str(target), str(reason), str(current_date), str(ctx.user))

# Function to register commands with the CommandTree
##def register(tree):
##    tree.add_command(kick)

@client.event 
async def on_ready():
  await client.change_presence(activity=discord.CustomActivity(name="Me is loves McBLock's Army", emoji="😀"))  #custom emoji <:McBlock:1200715339839836250>
  print("🥇kick.py is ready")
  print(f"Client name: {client.user}")
  print(f"Id: {client}")

client.run(os.environ['TOKEN'])

It specifies an object that is of type PartialEmoji

Therefore simply using the string will not work.

PartialEmoji provides a class method from_str that converts a Discord string representation of an emoji, or assumes its a Unicode emoji.

https://discordpy.readthedocs.io/en/stable/api.html?highlight=change_presence#discord.PartialEmoji

1 Like

Could you help me with the code? I don’t understand the docs

Simply use PartialEmoji.from_str if you want to obtain the emoji for usage in setting the Discord activity.

3 Likes

Did i understand it right:

import discord
from discord import app_commands
#Do i need line 4?
from discord import partial_emoji

import kick.kick_log
import ban.ban_log
import timee.time

import os


intents = discord.Intents.all()
client = discord.Client(intents=intents)
guild = client.guilds
tree = app_commands.CommandTree(client)

kick_file = kick.kick_log
tkick_file = timee.time
current_date = tkick_file.current_date

ban_file = ban.ban_log
tban_file = timee.time
current_date = tban_file.current_date

# Define your kick command
@tree.command(
    name="kick",
    description="Kicks a Target",
    guild=discord.Object(id=786934479812952085)
)
async def kick(ctx, target: discord.User, reason: str):
    # Kick logic...
  if ctx.user.guild_permissions.kick_members:
    await ctx.response.send_message(f"'Kicked' {target} for {reason} by {ctx.user} date: {current_date}. perms: {ctx.user.guild_permissions}")
    print(f"'Kicked' {target} for {reason} by {ctx.user} date: {current_date}.")
    kick_file.log_function(str(target), str(reason), str(current_date), str(ctx.user))



# Define your kick command
@tree.command(
    name="ban",
    description="Bans a Target",
    guild=discord.Object(id=786934479812952085)
)
async def ban(ctx, target: discord.User, reason: str):
    # Kick logic...
  if ctx.user.guild_permissions.ban_members:
    await ctx.response.send_message(f"'Banned' {target} for {reason} by {ctx.user} date: {current_date}. perms: {ctx.user.guild_permissions}")
    print(f"'Banned' {target} for {reason} by {ctx.user} date: {current_date}.")
    ban_file.log_function(str(target), str(reason), str(current_date), str(ctx.user))


# Function to register commands with the CommandTree
##def register(tree):
##    tree.add_command(kick)

@client.event 
async def on_ready():
  await client.change_presence(activity=discord.CustomActivity(name="Me is loves McBLock's Army", emoji= Partial.from_str("<:mcblock:1200715339839836250")))
  #is line 61 right or wrong?
  print("🥇kick.py is ready")
  print(f"Client name: {client.user}")
  print(f"Id: {client}")

client.run(os.environ['TOKEN'])

If you ment this, in line 61 it sais: “Partial” not defined.

I feel a bit dumb

Reading the docs states its called PartialEmoji, not Partial.

When I say PartialEmoji.from_str I mean it literally.

@PhoenixStarlight
sorry forgor to tell you I figured out how to do it. but still thanks a lot. But the sus thing is it still shows no emoji? where should I see it? or is it an unpublished feature?

line 1-4:

 import discord
from discord import partial_emoji

normal_emoji = discord.PartialEmoji(name="McBlock",id=1200715339839836250)

line 71-79:

@client.event 
async def on_ready():
 await client.change_presence(activity=discord.CustomActivity(name="Me is loves McBLock's Army", emoji=normal_emoji))

 print("🥇kick.py is ready")
 print(f"Client name: {client.user}")
 print(f"Id: {client}")

client.run(os.environ['TOKEN'])

Which library are you even using? I don’t even understand which library is being used.

To amend my reply:

If you read the documentation that I have linked you would not be having any issues with this!

Also the FAQ says how to get an emoji, too. (Its very similar to the provided from_str method of PartialEmoji)

There is no import for partial_emoji, so drop that.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.