Changing Presence Discord Status

How to change activity of a discord.py bot?

You can use the following lines of code, depending on which activity you want to change the bot to:

# Setting `Playing ` status
await bot.change_presence(activity=discord.Game(name="a game"))

# Setting `Streaming ` status
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))

# Setting `Listening ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))

# Setting `Watching ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))

Reference:

bot.change_presence

How can I change client presence with a command? Discord.py

This error is telling you that status is a string and not something that can iterated so a list.

Change this line:
await client.change_presence(activity=discord.Game(next(status)))

to:

await client.change_presence(activity=discord.Game(status))

Errors says change_presence is not an attribute to NoneType when using Discord.py

Bot is the Client subclass. you needn't it. try it:

class Bot(commands.Bot):
def __init__(self):
super().__init__(command_prefix=_prefix_callable,
help_attrs=dict(hidden=True))
self.token = credentials['token']
# self.client = discord.Client() <removed>

for extension in INITIAL_EXTENSIONS:
try:
self.load_extension(extension)
except Exception as e:
print('Failed to load extension {}\n{}: {}'.format(extension, type(e).__name__, e))

async def on_ready(self):
print('Logged in as:')
print('Username: ' + self.user.name)
print('ID: ' + str(self.user.id))
print('------')
# await self.client.change_presence(status=discord.Status.idle,
# activity=discord.Game(name="can help")) <old>
await self.change_presence(status=discord.Status.idle,
activity=discord.Game(name="can help"))

# async def close(self):
# await super().close() <what different hear?>

def run(self):
super().run(self.token, reconnect=True)


if __name__ == '__main__':
bot = Bot()
bot.run()

Change status when bot joins server | discord.py

First of all, the chng_pr function will loop every two minutes, so it's kinda useless to change the presence when a bot joins a guild. But if you really want you can delete that while loop and call it when the bot joins a guild. If you also want it to look every 2 minutes you can use discord.ext.tasks.

Here's how you should change the function.

async def chng_pr():
"""Changes presences"""
statuses = [f"-help | {len(client.guilds)} servers", f"-setup | {len(client.guilds)} servers", f"-vote | {len(client.guilds)} servers", f"-patreon | {len(client.guilds)} servers"]

status = random.choice(statuses)

await client.change_presence(activity=discord.Game(status))

Here's how to change the presence when the bot joins a guild.

@client.event
async def on_guild_join(guild):
await chng_pr()

Here's how to make a task and run in on the on_ready event

from discord.ext import tasks

@tasks.loop(minutes=2)
async def change_presence():
"""Will loop every two minutes and change presences"""
await chng_pr()


@client.event
async def on_ready():
await client.wait_until_ready()
# Starting the loop
change_presence.start()

You can also make it to be used in a command.

Note: This needs intents.guilds

Discord.js bot random presence and status not showing nor changing when the bot starts

setInterval actually waits for the specified delay (15 minutes) before executing the code in the function for the first time. So all you need to do is simply add pickPresence() on the line before the setInterval.

pickPresence();
setInterval(pickPresence, 1000*60*15);


Related Topics



Leave a reply



Submit