I don't have much knowledge on Python, and still in the process of learning it.
I have been significantly modifying an open-source Discord bot coded in Python 2.7.
I would like to add a feature that allows me to kick a user based on a command.
Something like [commandprefix]kickuser [userid] But I have no idea how to make the bot grab the userid from the message I sent, and when I try to make it ultra-specific to kick my second account as a test, it doesn't work either.
if message_content == ',purgeIdiots':
await kick('userid')
return
That's the ultra-specific code where I manually enter a userID into the document. But I cannot get it to work.
I'm extremely new and I'd appreciate some help.
If you're looking into the process of making commands, I'd suggest looking further into reading about the discord.ext.commands sub-library of discord.py.
Here's an FAQ about it, and an example of a bot using it following:
This extension will allow you to create commands using prefixes.
In regards to your question about kicking via user id, with the command extension you could do something like:
I believe that should work, but I can't compile it just yet to check. However, do learn more about the command extension as it'll help you out a lot more than checking messages for content.
You'll first need to import discord.ext, you can do that with
from discord.ext import commands
at the top of the program.You'll then need to define bot to ensure you can use stuff like
@bot.command
, because you'll need that. This is done like this:bot = commands.Bot(command_prefix=',', description=description)
, with the comma being defined as the command prefix now.This should allow the code snippet I added originally to function with a user being able to type
,kick <username>
.