Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python I'm writing a bot so that people don't give themselves money from the bot unbelievaboat?

Sco0b

Coder
I am writing a bot so that people do not give themselves money from the bot unbelievaboat.
There is such a bot for the economy. I want when people write add-money, the bot responds to them with remove-money
like they are trying to give money and the bot takes it.
I wrote the code, the bot writes a command, but nothing happens if the same command is written manually, everything is ok.

code:

Code:
import discord
import time

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.content.startswith('!add-money'):
time.sleep(2);
await message.channel.send(f"!remove-money {message.author.mention} 100")

client.run('TOKEN')
 
Solution
Okay, hopefully THIS will work:
Code:
import discord
from discord.ext import commands
from time import sleep

client = discord.Client()

client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print(f"Logged in as {client.user} (ID: {client.user.id}).")
 
@client.command(name="add-money")
async def _removemoney(ctx, member:discord.Member):
    sleep(2)
    role = discord.utils.get(ctx.guild.roles, name="Banned")
    await ctx.author.add_roles(role)

client.run("TOKEN")
This should work

Python:
import discord
from discord.ext import commands
from time import sleep

client = discord.Client()

client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print(f"Logged in as {client.user} (ID: {client.user.id}).")
 
@client.command(name="add-money")
async def _removemoney(ctx, member:discord.Member):
    sleep(2)
    await ctx.send(f"!remove-money {member.mention} 100")

client.run("TOKEN")

NOTE: This will only work if the unbelievaboat bot's prefix is '!'.
 
Last edited:
you don't know how to make unbelievaboat accept my bot's commands
if it does not work out so that unbelievaboat understands my bot, help me make it so that he gives the role of banned when the message is sent
 
There is no way to make unbelievaboat accept commands from a bot. Try this (there has to be a role called 'Banned' in the server):

Python:
import discord
from discord.ext import commands
from time import sleep

client = discord.Client()

client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print(f"Logged in as {client.user} (ID: {client.user.id}).")
 
@client.command(name="add-money")
async def _removemoney(ctx, member:discord.Member):
    sleep(2)
    member.add_roles("Banned")

client.run("TOKEN")
 
Try this:

Python:
import discord
from discord.ext import commands
from time import sleep

client = discord.Client()

client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print(f"Logged in as {client.user} (ID: {client.user.id}).")
 
@client.command(name="add-money")
async def _removemoney(ctx, member:discord.Member):
    sleep(2)
    server = ctx.message.guild
    roles = member.roles
    role = get(server.roles, name="Banned")
    await member.add_roles(role)

client.run("TOKEN")
 
Okay, hopefully THIS will work:
Code:
import discord
from discord.ext import commands
from time import sleep

client = discord.Client()

client = commands.Bot(command_prefix="!")

@client.event
async def on_ready():
    print(f"Logged in as {client.user} (ID: {client.user.id}).")
 
@client.command(name="add-money")
async def _removemoney(ctx, member:discord.Member):
    sleep(2)
    role = discord.utils.get(ctx.guild.roles, name="Banned")
    await ctx.author.add_roles(role)

client.run("TOKEN")
 
Solution

Latest posts

Buy us a coffee!

Back
Top Bottom