So basically what I am doing is trying to write a very basic kick and ban command to use for my discord bot. I've looked through many different tutorials and similar questions asked, but I simply cannot find a fix to this.
#bot.command()
#commands.has_permissions(kick_members=True)
async def kick(ctx, user: discord.Member, *, reason=None):
await ctx.kick(reason=reason)
await ctx.send(f"{user} has been kicked successfully")
When I have the bot up and running, everyone is able to kick everybody else regardless of whether they have permissions to kick members or not, even though I have specified it to check if the user is able to kick people. I want it so that if a user does not have permissions to kick members, they shouldn't be able to kick anyone. I am fairly new to coding, and any help is appreciated. If anyone would like to check for the rest of the code in my program, I am happy to post it, but for now I don't see a reason to have to.
await ctx.kick(reason=reason)
You're trying to kick the context. Kick the member instead:
await user.kick(reason=reason)
Related
import discord
from discord.ext import commands
bot = discord.Bot(command_prefix='!')
#bot.event
#commands.has_permissions(administrator=False)
async def delmessage(message):
await message.delete()
As explained by stijndcl in comment, the best solution is to go directly in your server settings to allow only admins and moderators to use #everyone and #here.
If you still you want to use a bot, something can easily be done using the on_message handler and then checking the roles of the message author to delete or keep the message.
The problem with this method is that the filtering process is done after the message publication, so deleting an unauthorized ping will create ghost pings and therefore a poor experience for your server members (and again why bother when a setting exists for this exact purpose).
I have a bot that currently does nothing other than keep itself hosted online
I have tried finding an answer to this but everything is for Javascript
basically what I'm looking for is a bot that:
When someone sends a message detect if he has role "X"
If he has role "X" reply with a prewritten message
for example, if someone has a role named "PlaysROR2"
whenever he types the word game the bot will send the message ROR2
I'm new to making discord bots and python in general so the more specific the answer the better
from what I understood there's no Has_role function so it's pretty complicated
#client.event
async def on_message(message):
role = discord.utils.get(message.guild.roles, name="PlaysROR2")
if role in message.author.roles and message.content == "game":
await message.channel.send("ROR2")
else:
return
Try this? I'm not very good at discord.py, sorry, and I haven't tested this yet so it might not work.
I'm looking into hosting an academic event in Discord. I need a bot that can check the presence of the enrolled in each activity, an activity being to watch seminars and alike through discord screensharing, so the adm team can have a secure track (if possible, with user email) of who can be awarded a certificate of participation. Would you know anything of this kind? Be it a ready-to-use bot or a source code.
The question is sadly wide, I'd like suggestions of any approaches that you could know.
(Edited)
It'll depend on exactly what you want, but here's something that should help if you're wanting to use discord.py.
import discord
client = discord.Client()
#client.event
async def on_ready():
vc = client.get_channel(id) #get the id of the voice channel
attend = vc.members
This will set attend to a list of members who were in the VC when you run the script. From there, you can do what you want with the list. For example, you could save a list of users' names to a file with this.
f = open('Attendees.txt', 'w')
f.write('\n'.join([user.name for user in attend]))
I'm trying to make a discord command where users can change what my bot is playing, but it changes for all servers and I don't want that. Is there a way to make it so that it only changes for the server that the user is sending the command from?
So far all I have is this
games={}
#bot.command(pass_context=True)
async def game(ctx, name):
server=ctx.message.server
games[server.name] = await bot.change_presence(game=discord.Game(name=name))
This is not possible as a Discord bot is only considered to have one websocket. You could make a loop and asyncio.sleep(time) to change the presence over time. Hope that helps!
I am trying to make it so server moderators are able to temporarily mute users in their Discord. I am not an experienced developer within Discord bots but learning.
What I am trying to do?
I am trying to make it so server owners are able to temp mute users in their Discord servers.
This is what I currently have for my Mute command:
#bot.command(pass_context=True)
async def mute(ctx, user: discord.Member):
if ctx.message.author.server_permissions.kick_members:
role = discord.utils.get(user.server.roles, name="Muted")
embed = discord.Embed(title="{} has been muted!".format(user.name), description="When the user needs unmuting do !unmute #user!" , color=0x0072ff)
embed.set_footer(text="Reversed by Damian#9209 | Reduction#9975")
embed.set_thumbnail(url=user.avatar_url)
await bot.add_roles(user, role)
await bot.say(embed=embed)
else:
embed = discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff0000)
embed.set_footer(text="Reversed by Damian#9209 | Reduction#9975")
await bot.say(embed=embed)
As I am sure you are aware, the Discord.py library has changed to no longer include the rewrite branch. This means that the mute command has been made way easier for you. I'll provide some code to get you started. I will also provide links to all the documentation to each line.
#bot.command(name="tempmute",description="Temporarily mute a member")
#commands.has_permission(mute_members=True)
async def _tempmute(ctx,user:discord.Member):
muteRole = discord.utils.get(ctx.guild.roles,name="Muted")
await user.add_roles(muteRole)
has_permission is a check for Discord user permissions
utils.get is a utility function that can step through iterables and find the correct search filter. Here, we are using it to find a role with the name "Muted"
add_roles is a coroutine function (aka needs to be awaited) that adds one or multiple roles to a user.
I suggest also making sure that the role has the speak permission disabled so that you don't have to deal with it through the on_message event. Hope that helps!