Larwive
Larwive

Reputation: 97

How to send slash commands with selfbot in Discord using Python?

I'm trying to send slash commands with a selfbot ran on repl.it but they are sent as normal message and not detected as commands.

Here's the code:

# coding=utf-8
import discord
import os
from keep_alive import keep_alive
from time import sleep
bot = commands.Bot(command_prefix="+", intents = discord.Intents.default())
def __init__(self, bot):
  self.bot = bot

@bot.event
async def on_ready():
  print("Logged in as {0.user}.".format(bot))
  while True:
    sleep(1)
    await bot.get_channel(farmchannel).send("/tableflip ")

farmchannel = CHANNEL_ID

keep_alive()
bot.run(os.getenv("token"), bot=False)

How to make it work?

I searched in the documentation of discord.py but I saw nothing that is made to send slash commands.

Upvotes: 3

Views: 7073

Answers (3)

boez
boez

Reputation: 717

I know this post is old but for everyone wondering: Discord.py doesnt support slash commands for selfbots, because selfbots are no longer supported by the library. However theres a library called Discord.py-self (mentioned by discord tehe), which is basically d.py for selfbots only (it can also be used for normal bots). To implement slash commands with dpy-self, heres a working solution:

import discord
from discord.ext.commands import Bot

client = Bot(command_prefix="!", self_bot=True, chunk_guilds_at_startup=False)

@client.command()
async def bump(ctx):
  channel = client.get_channel(ctx.channel.id)
  async for command in channel.slash_commands():
    if command.name == "bump":
       await command(channel)

client.run("token")

First we get the current channel to send the slash command, then we use a for loop to go through all slash commands in that channel until we get to the wanted slash command and then send it (you can also go through the slash command ids).

Upvotes: 1

discord tehe
discord tehe

Reputation: 101

/tableflip is not a slash command btw. It's built into the client and all it does is put the table flip text at the end of your message. You can replicate this functionality by sending a msg appended to (╯°□°)╯︵ ┻━┻

For actual slash commands (like "/8ball how is the weather" or "/saved queue list" or whatever) you can use discum's bot.triggerSlashCommand(...) function in the development branch.

There are 2 examples here: https://github.com/Merubokkusu/Discord-S.C.U.M/blob/development/examples/slashcommands.py

The reason for the 2 examples is that there are 2 ways slash commands are triggered (since searching for slash cmds in DMs is done by rest requests but searching for slash cmds in guilds is done by websocket communications). It doesn't really matter which example you use for which situation.

If you want to mimic the client, use the 1st example in guilds and the 2nd example in DMs.

Finally, if you don't want to use a synchronous api wrapper like discum, you can use discord.py-self. I heard that they will implement slash commands sometime soon.

Upvotes: 4

scold.zing
scold.zing

Reputation: 9

Try using character code

await bot.get_channel(farmchannel).send(chr(47) + “tableflip ")

Upvotes: 0

Related Questions