Discord.py Self Bot using rewrite - python

I'm trying to make a selfbot using discord.py rewrite.
I'm encountering issues when attempting to create a simple command.
I'd like my selfbot to respond with "oof" when ">>>test" is sent.
Here is my code:
import asyncio
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=(">>>"), self_bot=True)
#bot.event
async def on_ready():
print("Bot presence t u r n e d on ( ͡° ͜ʖ ͡°)")
#bot.command()
async def test(self, ctx):
await self.bot.say("oof")
bot.run("my token", bot=False)

A self-bot isn't a bot that uses self, it's a bot that logs in using your credentials instead of a bot account. Self bots are against the Discord TOS (and you're not doing anything that requires one), so you should set up a bot account through their website and use a bot account for your bot.
That said, bot.say has been replaced by ctx.send in rewrite, and you're not in a cog so you shouldn't use self as all.
from discord.ext import commands
bot = commands.Bot(">>>", self_bot=True)
#bot.event
async def on_ready():
print("Bot presence t u r n e d on ( ͡° ͜ʖ ͡°)")
#bot.command()
async def test(ctx):
await ctx.send("oof")
bot.run("my token", bot=False)

Related

Your message was not delivered. Discord bot

I'm making a discord bot. when I send commands on the server from my account with the owner role, then everything is OK, it is executed.
photo_1
If I switch to another account that has the everyone role, then the bot stupidly does not react.
photo_2
here is a piece of code:
import discord
from discord.ext import commands
from dislash import InteractionClient, Option, OptionType
bot = commands.Bot(command_prefix='!')
inter_client = InteractionClient(bot)
#bot.event
async def on_ready():
print('Bot is launch!')
#inter_client.slash_command(description="Says Hello")
async def hello(ctx):
await ctx.respond(content='asfd', ephemeral=True)
bot.run(token)

How to give discord roles with a bot

Im using the discord.py library and using replit for the bot, but my code doesnt work.
my code:
import os
import discord
from discord.utils import get
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 == ";":
member = message.author
role = get(member.guild.roles, name="Recruiter")
await member.add_roles(role)
client.run(os.getenv("TOKEN"))
First of all, you're using client object and it is not a bot.
This is the way to create a proper bot (not client):
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
You can't code reactions roles without reading the discord.py docs. It involves lots of stuff.
If you want to code it yourself, the only way is to learn and do.

The 'Asyncio' event loop isn't working [Discord PY]

I've started to try coding a discord bot but it was cut short when setting a prefix and events wouldn't work. It just displays an error message that says 'the command "hello" can not be found'.
import discord
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix="*" ,status=discord.Status.idle, activity=discord.Game("Starting up..."))
#client.event
async def on_ready():
await client.change_presence(status=discord.Status.do_not_disturb, activity=discord.Game("Preparing Puzzle Event"))
print("Bot is running.")
#client.event
async def hello(ctx):
await ctx.send("Hi")
client.run('[The token]')
I know that the token is valid as I've ran it before without assigning a prefix and using 'async'.
#client.event
async def hello(ctx):
await ctx.send("Hi")
This won't work because hello is not a built-in event. See: https://discordpy.readthedocs.io/en/latest/api.html#discord-api-events
What you want is a command probably
#client.command()
async def hello(ctx):
await ctx.send("Hi")
This registers the bot to respond to the command .hello assuming . is your prefix

I'm very new to making discord bots with python and for some reason the bot doesn't respond to commands

As described in the title, I am new to Python(programming in general) and I tried making a bot, however the bot does not respond to commands. I followed/looked through multiple youtube tutorials & articles, but I cannot find a way to fix my problem.
import discord
from discord.ext.commands import Bot
bot = Bot(".")
#bot.event
async def on_ready():
print("kram is now online")
await bot.change_presence(activity=discord.Game(name="This bot is a WIP"))
#bot.event
async def on_message(message):
if message.author == bot.user:
#bot.command(aliases=["gp"])
async def ghostping(ctx, amount=2):
await ctx.send("#everyone")
await ctx.channel.purge(limit = amount)
#bot.command()
async def help(ctx):
await ctx.send("As of right now, .gp is the only working command.")
bot.run("I'm hiding my token")
Hey why don't you try this instead the same thing but i removed the on message
import discord
from discord.ext.commands import Bot
bot = Bot(".")
#bot.event
async def on_ready():
print("kram is now online")
await bot.change_presence(activity=discord.Game(name="This bot is a WIP"))
#bot.command(aliases=["gp"])
async def ghostping(ctx, amount=2):
await ctx.send("#everyone")
await ctx.channel.purge(limit = amount)
#bot.command()
async def help(ctx):
await ctx.send("As of right now, .gp is the only working command.")
bot.run("I'm hiding my token")
This should work as when using cogs and when you have a command there is no need to put it in the on_message event. i suggest you watch this series(Really helpful while starting out):
https://www.youtube.com/watch?v=yrHbGhem6I4&list=UUR-zOCvDCayyYy1flR5qaAg

Discord Python Bot: How to move specific users mentioned by the author of the message

I am looking for a way to allow a user to move him or her self and another user to a different voice channel. I already got the command to work for the author of the message, but I am having trouble finding out a way to move another user in the same message. The idea is that the user would be able to type "n!negotiate [Other User]" and it would move the author and the other user to the Negotiation channel.
I would love some help with how I might be able to do this. The code is provided below excluding the tokens and ids.
Code:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
Client = discord.Client() #Initialise Client
client = commands.Bot(command_prefix = "n!") #Initialise client bot and prefix
#client.event
async def on_ready():
print("Logged in as:")
print(client.user.name)
print("ID:")
print(client.user.id)
print("Ready to use!")
#client.event
async def on_message(check): #Bot verification command.
if check.author == client.user:
return
elif check.content.startswith("n!check"):
await client.send_message(check.channel, "Nations Bot is online and well!")
async def on_message(negotiation): #Negotiate command. Allows users to move themselves and other users to the Negotiation voice channel.
if negotiation.author == client.user:
return
elif negotiation.content.startswith("n!negotiate"):
author = negotiation.author
voice_channel = client.get_channel('CHANNELID')
await client.move_member(author, voice_channel)
client.run("TOKEN")
You should use discord.ext.commands. You're importing it, but not actually using any of the features.
from discord.ext import commands
import discord
bot = commands.Bot(command_prefix = "n!") #Initialize bot with prefix
#bot.command(pass_context=True)
async def check(ctx):
await bot.say("Nations Bot is online and well!")
#bot.command(pass_context=True)
async def negotiate(ctx, member: discord.Member):
voice_channel = bot.get_channel('channel_id')
author = ctx.message.author
await bot.move_member(author, voice_channel)
await bot.move_member(member, voice_channel)
bot.run('TOKEN')
Here we use a converter to accept a Member as input. Then we resolve the author of the message from the invocation context and move both Members to the voice channel.

Categories

Resources