Remove default help command not working discord.py - python

So I'm trying to remove the default help command from my discord bot but it shows my new one and the old one (Example Image), even though I have the code that removes it.
So to remove it I'm using
client = commands.Bot(command_prefix = '!',help_command=None)
and to replace it I have
#client.command()
async def help(ctx):
embed = discord.Embed(
colour = discord.Colour.orange()
)
embed.set_author(name='Saint Bot the Third Help Page')
embed.add_field(name='!remind', value='Reminds Shabby to get a PC', inline=False)
embed.add_field(name='!play', value='Gives you a random game to play', inline=False)
await ctx.send(embed=embed)
I have also tried using
client.remove_command("help")
but that did not work either

try this again, you will have to write all the errors thrown if there are any,
i have checked this code, and it is working fine.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '!')
client.remove_command("help")
#client.command()
async def help(ctx):
embed = discord.Embed(
colour = discord.Colour.orange()
)
embed.set_author(name='Saint Bot the Third Help Page')
embed.add_field(name='!remind', value='Reminds Shabby to get a PC', inline=False)
embed.add_field(name='!play', value='Gives you a random game to play', inline=False)
await ctx.send(embed=embed)
client.run(token)

Related

How do you make a bot that sends a welcome embed and deletes the embed after a few seconds in discord.py

Here's my code but it seems like it doesn't work. I'm so sorry but, I'm still a newbie but, I would very much appreciate your help and critics.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
intents=discord.Intents.all())
#client.event
async def on_message_join(member):
channel = client.get_channel(channelid)
count = member.guild.member_count
embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count)
embed.set_thumbnail(url=member.avatar_url)
await channel.send(embed=embed)
time.sleep(5)
message.delete(embed)
The correct discord event to catch that a person joins your discord is:
async def on_member_join(member: discord.Member):
rather than on_message_join
To easily delete the message you can first make it a string:
msg = await channel.send(embed=embed)
then get it's id by:
msg_id = msg.id
then fetch it:
msg_todel = await channel.fetch_message(int(msg_id))
then delete it:
await msg_todel.delete()
Just use delete_after=seconds, this exactly what's your wanted
import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
intents=discord.Intents.all())
#client.event
async def on_message_join(member):
channel = client.get_channel(channelid)
count = member.guild.member_count
embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count)
embed.set_thumbnail(url=member.avatar_url)
await channel.send(embed=embed, delete_after=5)
According to the discord.py docs, you could edit the message object after 5 seconds and then just set the new embed parameter to None, this seems to be what you're after here.
Below is a way you can alter your code to do this.
import discord
import asyncio # You will need to import this as well
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
intents=discord.Intents.all())
#client.event
async def on_message_join(member):
channel = client.get_channel(channelid)
count = member.guild.member_count
embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count)
embed.set_thumbnail(url=member.avatar_url)
message_object = await channel.send(embed=embed) # You can save the message sent by attaching it to a variable. You don't need to send more calls to refetch it.
'''
time.sleep(5) <--- You should not use time.sleep() as it will stop your entire bot from doing anything else during these 5 seconds.
Use asyncio.sleep() as a better alternative. Does the same thing as time.sleep() but other functions of your bot will still function, this is called a blocking function.
'''
asyncio.sleep(5)
await message_object.edit(embed = None)
Unless you want the entire message deleted, then you can just use delete_after in order to obtain this.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
intents=discord.Intents.all())
#client.event
async def on_message_join(member):
channel = client.get_channel(channelid)
count = member.guild.member_count
embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count)
embed.set_thumbnail(url=member.avatar_url)
await channel.send(embed=embed, delete_after = 5) # Just add this parameter at the end.

Closed Pycharm without disconnecting, and discord bot still running

I am a new programmer, trying to make a discord bot with python. Today I closed PyCharm, and did not close the running program first. As soon as I did that, the discord.py bot was still running in discord. All the commands were working with it, and the bot was online. When I restarted Pycharm, I ran the program again, and then it started working twice, and when I terminated the program, the bot was still running in discord. Here is my code and an image of what is happening-
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='r!', case_insensitive=True)
client.remove_command('help')
#client.event
async def on_ready():
print(f'{client.user.name} is ready')
#client.command()
async def help(ctx):
embed = discord.Embed(
title='Training Bureau Bot',
description='''These are all the commands you can use from this bot:
----------------------------------------------------------''',
color=discord.Colour.gold()
)
embed.set_thumbnail(url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')
embed.add_field(
name='r!help',
value='`Shows all the commands.`',
inline=True
)
await ctx.send(embed=embed)
#client.command()
async def discharge(ctx):
allowed_people = discord.utils.get(ctx.guild.roles, name='Training Bureau Personnel')
if allowed_people in ctx.author.roles:
embed = discord.Embed(
title='Discharge',
description='''If you want to discharge, state your reason below.
---------------------------------------------------------''',
color=discord.Colour.gold()
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')
await ctx.send(embed=embed)
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel and \
msg.content.lower()
msg = await client.wait_for('message', check=check, timeout=60)
embed_2 = discord.Embed(
title='Successful!',
description='Your discharge has been successfully logged. Please wait for the HICOM to accept/deny it.',
color=discord.Colour.green()
)
embed_2.set_thumbnail(
url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')
discharge_logs = client.get_channel(933708007097905183)
embed_3 = discord.Embed(
title='Discharge Notice',
description=f'{msg.author.display_name} has written a discharge notice with the reason: "{msg.content}"\n' + '----------------------------------------------------------------------------',
color=discord.Colour.gold()
)
embed_3.set_thumbnail(
url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')
await discharge_logs.send(embed=embed_3)
await ctx.send(embed=embed_2)
else:
embed = discord.Embed(
title='No permissions',
description='You are not allowed to execute this command. (If you think this is a mistake, DM Burger1372.',
color=discord.Colour.red()
)
await ctx.send(embed=embed)
client.run(TOKEN)
Please tell me how to fix this. If you could also tell me how I can make the code more efficient, it would be appreciated. :)

Message Will Not Send To Channel w/ Discord.py

I am programming a discord bot that will send an embed to a separate channel when someone uses a command to prevent abuse and so our admins can keep an eye on usage.
I have this code:
#client.command()
#has_permissions(manage_messages=True)
async def purge(ctx, amount=5):
await ctx.channel.purge(limit = amount + 1) # Plus one is so that it also deletes the players purge message
embed = discord.Embed(title="Purged Channel", description="", colour=0xe74c3c, timestamp=datetime.utcnow())
embed.set_author(name="CS Moderation", icon_url="https://cdn.discordapp.com/attachments/938857720268865546/938863881726615602/ca6.png")
embed.add_field(name="Staff Member", value=ctx.author.mention, inline=False)
embed.set_footer(text="Made by HeadOfTheBacons#6666", icon_url=None)
channel = client.get_channel("938898514656784404") #Change ID of logging channel if needed
await channel.send(embed = embed)
When I run this, I cannot get the embed to be sent to a different channel. I have tried checking other posts already but I have not had much luck at all. I have no errors when I use the command or try to run the bot. The point here is when someone uses the command to make a new embed, set up the preferences, specify the specific channel ID where I want this embed to be sent to, and have the computer send it off to that channel. However, it is not sending. Why is my code not working? What do I need to change in my code to make this send a message?
Check if you have an on_command_error function in your program, it could be the reason of your no error problem.
Also not that the embed.footer can't be None, and the client.get_channel requires an Integer.
So you can try out the following code, it should work:
from datetime import datetime
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
client = commands.Bot(command_prefix="prefix")
#client.command()
#has_permissions(manage_messages=True)
async def purge(ctx, amount=5):
await ctx.channel.purge(limit=amount + 1) # Plus one is so that it also deletes the players purge message
embed = discord.Embed(title="Purged Channel", description="", colour=0xe74c3c, timestamp=datetime.utcnow())
embed.set_author(name="CS Moderation", icon_url=client.user.avatar_url)
embed.add_field(name="Staff Member", value=ctx.author.mention, inline=False)
embed.set_footer(text="Made by HeadOfTheBacons#6666")
channel = client.get_channel(938898514656784404) # Change ID of logging channel if needed
await channel.send(embed=embed)
client.run("TOKEN")

How to stop repetitive messages, and the token is changed, but it doesn't run

I started learning python today and made a Discord bot. I have a few problems:
If message.author == was used in the on_message, but the bot continued to reply to itself.
Afterwards, a new bot was created with a new token and the code didn't work.
I searched a lot on this site and Google. I didn't find any solution. It's okay to modify my code. Everything is from the internet, so it can be a mess. Please help me.
import discord
import asyncio
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix="!")
#bot.event
async def on_ready():
print('Loggend in Bot: ', bot.user.name)
print('Bot id: ', bot.user.id)
print('connection was succesful!')
print('=' * 30)
#client.event
async def on_message(message) :
if on_message.content.startswith('!의뢰'):
msg = on_message.channel.content[3:]
embed = discord.Embed(title = "브리핑", description = msg, color = 0x62c1cc)
embed.set_thumbnail(url="https://i.imgur.com/UDJYlV3.png")
embed.set_footer(text="C0de")
await on_message.channel.send("새로운 의뢰가 들어왔습니다", embed=embed)
await client.process_commands(message)
client.run("My bot's token.")
Your code was messy, but it should work now. I included comments to let you know how everything works. I think the good starting point to making your own bot is reading documentation. Especially Quickstart that shows you a simple example with explanation.
Write !example or hello to see how it works.
import discord
import asyncio
from discord.ext import commands
# you created 'client' and 'bot' and used them randomly. Create one and use it for everything:
client = commands.Bot(command_prefix="!") # you can change commands prefix here
#client.event
async def on_ready(): # this will run everytime bot is started
print('Logged as:', client.user)
print('ID:', client.user.id)
print('=' * 30)
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('hello'): # you can change what your bot should react to
await message.channel.send("Hello! (This is not a command. It will run everytime a user sends a message and it starts with `hello`).")
await client.process_commands(message)
#client.command()
async def example(ctx): # you can run this command by sending command name and prefix before it, (e.g. !example)
await ctx.send("Hey! This is an example command.")
client.run("YOUR TOKEN HERE")

discord.py - adding reaction as part of command

I'm writing a custom help command that sends a embed DM to a user, that all works fine. As part of the command, I'm trying to make the bot react to the command message but I cannot get it to work, I've read the documentation but I still can't seem to get it to react as part of a command. Below is the what I'm trying to achieve:
#client.command(pass_context=True)
async def help(ctx):
# React to the message
author = ctx.message.author
help_e = discord.Embed(
colour=discord.Colour.orange()
)
help_e.set_author(name='The bot\'s prefix is !')
help_e.add_field(name='!latency', value='Displayes the latency of the bot', inline=False)
help_e.add_field(name='!owo, !uwu, !rawr', value='Blursed commands', inline=False)
await author.send(embed=help_e)```
You can use message.add_reaction() and also you can use ctx.message to add reaction to the message. Here is what you can do:
#client.command(pass_context=True)
async def help(ctx):
# React to the message
await ctx.message.add_reaction('✅')
author = ctx.message.author
help_e = discord.Embed(
colour=discord.Colour.orange()
)
help_e.set_author(name='The bot\'s prefix is !')
help_e.add_field(name='!latency', value='Displayes the latency of the bot', inline=False)
help_e.add_field(name='!owo, !uwu, !rawr', value='Blursed commands', inline=False)
sent_embed = await author.send(embed=help_e)

Categories