I am currently working on a command to change a user's nick name.
The bot currently has admin privileges, and the admin role is at the top of the role's list.
However, whenever I run the command, I keep getting this error:
Command raised an exception: Forbidden: FORBIDDEN (status code: 403): Privilege is too low...
The code for the cog is
from discord.ext import commands
from discord.ext.commands import Bot
import discord
class CMDs():
def __init__(self, bot):
self.bot = bot
#commands.command()
async def change(self, ctx):
await ctx.message.author.edit(nick="test")
def setup(bot):
bot.add_cog(CMDs(bot))
When I googled my problem, the solution was to move the role to the top of the role's list, but that did not work (because I keep getting the error). Does anyone else have any ideas on how I might get this to work?
Nobody has or can gain permission to modify the nickname of the guild's owner. This command as written however will work for every other user except the owner.
Related
I have multiple discord bots but suddenly, they all just stopped responding to my commands. I copied this code from online to see if there was a problem with my code, but this doesn't seem to work either. When I type in "$hello", nothing happens. The bot goes online when it runs but doesn't do anything aside from that. I have double-checked my python is up to date, the bot has server roles and permissions, tried it on multiple servers, and ensured that the bot has admin permissions on the discord developer portal. I'm not sure what else could be wrong. It may just be a coincidence but I installed some discord-ui packages when the problem occurred. However, I did uninstall it and the bot still does not work. And yes, my real token is in the code.
import discord
client = discord.Client()
#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('$hello'):
await message.send('Hello!')
client.run('MY TOKEN IS HERE')
If you copy it from somewhere else, they probably don't do it right (proof: here and here). After checking the docs (to check is my guess is right), it's await message.channel.send('things'), not await message.send('Hello!'). So to fix it, change to this:
import discord
client = discord.Client()
#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('$hello'):
await message.channel.send('Hello!')
client.run('MY TOKEN IS HERE')
PS: Because you only show the copied code, I only answer that code
It because of Message Intent. Your bot won't see message content if it is disabled. Of course you can just turn it on but it is recommended to use slash commands. discord.py has no support for slash commands, so I'll recommend to use pycord.
Here is short example of slash command
import discord
bot = discord.Bot()
#bot.slash_command()
async def hello(ctx, name: str = None):
name = name or ctx.author.name
await ctx.respond(f"Hello {name}!")
bot.run("token")
Pycord documentation
#client.command()
async def eventsoon(ctx):
role = discord.utils.get(ctx.message.guild.roles, name='Golden God')
for member in ctx.message.guild.members:
if role in member.roles:
await member.send("ur mom")
I want the bot to dm users with golden god role, it doesnt work aand gives no errors
I tested your code and it's probably happening because you didn't enable Privileged Gateway intents and your bot can't get all members. Enable Server Members Intent on the Discord Developer site in the Bot section.
Then, add them to your code. Example:
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="!", intents=intents)
I recently receive a 2 message in discord with invite link to server I received it from bot who doesn't share the same server with me or anything
How this is possible, I find some py codes but only work if the user and bot share same server
from discord.ext.commands import Bot, Greedy
from discord import User
bot = Bot(command_prefix='!')
#bot.command()
async def pm(ctx, users: Greedy[User], *, message):
for user in users:
await user.send(message)
bot.run("TOKEN")
How can I make one send messages to list of IDs not in same server?
Maybe the bot left the server after he sent the invite to everyone.
You could check if one of the bots was in the servers in the audit-log.
you could either get the user by id with the guild.get_member(id). That requires the user to be on that specific guild you try to get the user.
Or you can use bot.get_user(id) / await bot.fetch_user(id). There the bot tries to get the user. If found you can do sth with it else it will return None or raises the command Error UserNotFound.
A bot that has no mutal guild with a specific user cannot send a dm to them.
Also what purpuse is it to send dms to multiple users from a list?
Keep in mind that its against the Discord TOS to mass dm users without permissions. If they did not opt in sth to get dms I would not send random dms do multiple users.
I am writing a Discord bot that assigns a role to new users when they join my Discord guild. Let's say the role is called "Friend".
The bot is written in Python and uses the Discord.py library.
I am overwriting the on_member_join() function.
#bot.event
async def on_member_join(member):
assign member to Friend role
I see that there is a add_roles() function from the Member class, but it hasn't worked in this case because the new member doesn't have permissions to manage roles. For security concerns, the default #everyone role shouldn't have the ability to manage roles and be able to assign whatever role it wants to be.
The Discord Bot does have permissions to manage roles.
Is there a way to have the bot automatically assign a new member to the Friend role?
Thank you.
Try this :
#bot.event
async def on_member_join(member):
role = discord.utils.get(member.server.roles, id="<role ID>")
await bot.add_roles(member, role)
Solved! Thanks Bagle for helping out.
Here is what worked:
#bot.event
async def on_member_join(member):
default_role = discord.utils.get(member.guild.roles, id=DEFAULT_ROLE_ID)
await member.add_roles(default_role)
DEFAULT_ROLE_ID is an integer of the role id I'm trying to assign.
Make sure that your bot has "Manage Roles" permission set AND is above the role you're trying to set in your Guild's role hierarchy.
For example, if your bot has a role of Bot and the role you're trying to auto assign is Friend, make sure Bot is above Friend in the "Roles" tab. If Bot is not above Friend, you'll hit an error.
I'm trying to hit the /guilds/{guildId} endpoint, and I've created a bot and installed it on the server I'm trying to access and even granted it admin access, but I'm still getting a "missing access" error:
In this case, Error 403 either means that the Bot is not in a guild with that id or that there is no guild with the id you provided in the URL.
Make sure, you copied the id of the correct server.
Double check if you are using the correct token and if you're posting to the right guild.
If the bot has administrator, it simply has access to all channels. This error means that the bot user either does not have permission or is not in that guild.