Discord Bot Status not automaticaly changing - discord.py

i am programming a Discord bot at the moment and I have the problem that if i have tabby open everything works fine, but if i close tabby everything still works except the status don't change anymore.
Thanks for your help!
Niklas
Here is my code:
#bot.event
async def precence():
await bot.change_presence(activity=discord.Game(name=f"{len(bot.guilds)} server"))
await asyncio.sleep(5)
await bot.change_presence(activity=discord.Game(name=f"{len(bot.users)} users"))
await asyncio.sleep(5)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="!help"))
await asyncio.sleep(5)
bot.loop.create_task(precence())
I din't try anything because i don't know what i should do.

Related

Hey, I just created a discord bot using PyCharm and its all going good, but when i try to send !hi or hi it doesnt send Hello back. can anyone help me

import discord
intents = discord.Intents(messages=True)
client = discord.Client(command_prefix='!', intents=intents)
import random
import time
import asyncio
TOKEN = "<My token>"
intents = discord.Intents(messages=True)
#client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("hi"): #whenever i type this
await message.channel.send("Hello") #i dont get this
#client.event
async def on_ready():
print("Running!")
client.run(TOKEN) #Token
thanks for the help,i just need the program to say hello when i say hi,
I am kinda new to making bots soo yeah. I copied this from a youtube vid, but the intents i did by myself. I am using 3.8 version of Python, it runs without errors
This may be because you did not update your intents or in general something wrong with the intents,
Intents on the discord developer portal are in the Bot Section,
If these are enabled then try printing message.content to see if it returns blank or what the user says.

How can I find the author of a post in discord.py?

I want to have my bot send a message that says "shut up" whenever my friend sends a message. I don't know where to start. How can I do this?
Make sure to replace "<YOUR FRIEND'S ID>" with your friend's user ID (right-click > Copy ID) {if you cannot see this, enable "Developer Mode" in Discord Advanced Settings}
#client.event
async def on_message(message):
if message.author.id == <YOUR FRIEND'S ID>:
await message.channel.send("shut up")
else:
return
await client.process_commands(message)

Discord bot responding to pings that aren't meant for the bot

For example, I want the bot to delete a message that pings the owner of the server.
I'm pretty new to python, I. currently only have the code that makes the bot run
You need to check on each message if the message.author mentions the server owner.
#bot.event
async def on_message(message):
# Check if message has mentions
if message.mentions:
# check if guild owner is in the mention list
if message.guild.owner in message.mentions:
# delete if yes
await message.delete()
Sources
On Message

How to send message on event from pc bot is running on? Not from message/channel?

have watchdog file observer. When specific file appears I obtain it and I want to send it into a discord channel.
What commands/events should I look at/use to do this? It's not coming from async discord function. Event is not coming from channel or message, but from obtaining of the file from the PC which bot is runnin on.
Thank you
I did not get the question well, though, if you want to do something when the bot comes online my suggestion is: use the on_ready event. Here is an example:
#client.event
async def on_ready():
await client.change_presence(activity=discord.Game('Hello!'))
print('Connected to bot: {}'.format(client.user.name))
print('Bot ID: {}'.format(client.user.id))

Cant get discord.py bot to disconnect from voice chat

I have gotten the connect to work fine, but when trying to get the bot to disconnect, it will print that it has disconnected and will just sit their in chat with no errors. Here's the code:
#client.command(pass_context=True)
async def join(ctx):
channel = ctx.message.author.voice.channel
await channel.connect()
print('connected')
#client.command(pass_context=True)
async def disconnect(ctx):
server = ctx.message.guild.voice_client
await server.disconnect()
print ('disconnected')
Thanks in advance for any help.
You may want to try using server.disconnect(force=True) (documentation) as sometimes disconnecting may be blocked if you don't force it.

Resources