How would I go about changing my bots avatar with a command such as pfpchange or something similar?
Any help would be appreciated, I've tried the following code with zero luck.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='=')
client.remove_command('help')
pfp = 'https://cdn.discordapp.com/attachments/751402019046162494/774903321844645968/pinkbulba.jpg'
#client.command()
async def pfpchange(ctx):
await client.edit_profile(password=None, avatar=pfp)
client.run('super secret token')
Bot.edit_profile() was renamed to ClientUser.edit(), which is why it doesn't work. You're supposed to use Bot.user.edit().
More info in the relevant API documentation
Related
I don't know how but I had got this working long ago, but I don't have the code anymore and I'm not even use if it was slash command or regular command.
As you can see this was me using the bot in my dms. Now I have a new bot and I'm trying to do this by adding the guild id of my personal account but it gives me this error
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
This is how my slash commands look like:
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
bot = commands.Bot(command_prefix='$', intents=Intents.all())
slash = SlashCommand(bot, sync_commands=True)
#slash.slash(name="test", guild_ids=[guild_id_of_server])
async def test(ctx: SlashContext):
...
And this works flawlessly in my server, I just want it to make it work in my dms. Should change the permissions of the bot?
You added guild_ids=[guild_id_of_server] so it will only work on server
#slash.slash(name="test", guild_ids=[guild_id_of_server])
async def test(ctx: SlashContext):
Just remove it and done!
#slash.slash(name="test")
async def test(ctx: SlashContext):
so i'm playing with discord bots a little bit.
My issue is that when I type one of my commands, it doesn't work and shows me this message: "discord.ext.commands.errors.CommandNotFound: Command "dadjoke" is not found" (this is an example but I have the same issue with all the commands I tried).
Here is my full code:
import discord
import requests
from discord.ext import commands
client = commands.Bot(command_prefix='.')
#Setup the client
#client.event
async def on_ready():
#connection
print(f'Ready and Logged in as {client.user}')
#Help
#commands.command(name='help')
async def help(ctx):
#Embed parameters
Help_Embed = discord.Embed(title=f"</{client.user}y Help>", description=f"{client.user} bot by Stan_#1423", color=0xfee010)
Help_Embed.add_field(name="Version code:", value="v0.1", inline=False)
Help_Embed.add_field(name="Day Released:", value="03/03/22", inline=False)
Help_Embed.add_field(name="Get a joke", value="type: '.dadjoke'", inline=True)
#Sending Embed
await ctx.send(embed=Help_Embed)
#Jokes
#commands.command(name='dadjoke')
async def dadjoke(ctx):
headers = {'Accept': 'text/plain',}
resp = requests.get('https://icanhazdadjoke.com/', headers=headers)
joke = resp.text
await ctx.send(joke)
#Run the client
client.run('TOKEN')
I have already looked it up on the internet and i didn't find anything that solved my problem, i also tried to copy some code i found on online courses and stuff, but i still had the same problem.
Thanks for helping and sorry for bothering you guys with my dumb problems.
If you are using prefixed commands, it should be
#client.command(name=‘whatever’)
I believe you should use #client.command() instead of commands.command().
I was following a tutorial for discord.py and the person who was teaching was getting pretty complicated.
He told use to create a main_cogs.py file and i did it.
This is the exact code as him:
import config
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='-')
class Test(commands.Cog):
def __init__(self,bot):
self.bot= bot
#commands.command
async def ping(self ,ctx):
await ctx.send("Pong")
bot.run(config.token)
BTW config is a file with the token and all that stuff.
When i run it and type -ping(in chat) i get this in the console and nothing in chat:
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "ping" is not found
for him it just works.
The video
Thank You for the help!
change
#bot.command() to #commands.command()
remove ctx from the def __init__(self,bot,ctx): so its def __init__(self, bot):
Hm, I use a different way of coding the bot, I'll show you my way of making a bot reply.
from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='-')
#bot.command()
async def ping(ctx):
await ctx.send('pong!')
bot.run('token')
and my opinion on the issue? It might be because of the indented block. Since that means that that would need to trigger for that to even exist in the first place. and the missing parentheses after the command is also probably an issue. 100% recommend you to remove the block and add the parentheses before just trying what I made.
I was dumb. I still am.
I DID NOT CALL THE FUNCTION!
So I'm having a problem with discord.py.
I'd like to make a command to kick/ban people.
I tried this at first and it didn't work, so I went to check if commands worked at all for me. Apparently it doesn't. I've tried everything and nothing works.
import discord
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix='!')
Token = 'TOKEN'
#bot.command(pass_context=True)
async def test(ctx):
await ctx.send('test')
client.run(Token)
I type !test on the channel but nothing happens.
I've tried basically everything.
I've changed the prefix, done: #bot.command(name='test), basically everything you could think of. Nothing works. I'd like to know if I'm missing something crucial. Like do I have to download something first or am I missing something in the code or are there permissions I need to enable. I've looked all over the discord py API reference. Anything would be helpful thanks.
Your problem is because of bot = commands.Bot(). You can use this code instead:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="!")
#client.command()
async def test(ctx):
await ctx.send('test')
client.run(token)
So you just have to delete bot = commands.Bot() then replace the #bot.command() with #client.command.
So im making a !suggest command for my discord server and i have it done except i need it to dm me the suggestion the person made. I can not find info on how to dm a specific person by ID or otherwise. Here is my coded command thus far:
async def suggest(server, suggestion):
await server.owner.create_dm()
await dm_channel.send("{} suggested this: '{}'".format(ctx.author.mention, suggestion))
Please help?
You can use client.get_user to get your own User object, which has a send method that will send a DM to you over Discord.
from discord.ext import commands
client = commands.Bot(command_prefix='!')
#client.command()
async def suggest(ctx, suggestion):
dm_user = client.get_user(1234567890) # Your Discord ID here
await dm_user.send("{} suggested this: '{}'".format(ctx.author.mention, suggestion))
client.run('token')