0

I have a discord.py bot that when the command is sent through DM, it works. When the command is ran through a server, nothing happens. There is no errors or tracebacks. Here is my code so far.

import discord
from discord.ext import commands

bot = discord.Bot()

TOKEN = "MyToken"

bot = commands.Bot(command_prefix="$")

@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)

bot.run(TOKEN)

I don't know whats happening. I gave it the right permissions but it still wont do anything.

6
  • 1
    Enable your intents in the developer portal and configure it in your bot. Commented Apr 21, 2022 at 19:03
  • @3nws how do I do that? Commented Apr 21, 2022 at 19:06
  • 1
    Check How do I get the discord.py intents to work?. Commented Apr 21, 2022 at 19:13
  • What is your discordpy version? If there's no errors, I would assume it's not the version where you get message intents yet. You should probably upgrade to the latest version. Commented Apr 21, 2022 at 20:04
  • @EricJin my version is 1.7.3, the latest version Commented Apr 22, 2022 at 12:51

2 Answers 2

1

So, I don't know for sure if this is the issue, but try this:

I have my bot set as:

bot = commands.Bot(command_prefix= '$', description="<desc>")

Rather than yours which is BOTH of these:

bot = discord.Bot()

&

bot = commands.Bot(command_prefix="$")

I think it's only detecting the first value you've given your bot.

Sign up to request clarification or add additional context in comments.

Comments

0

For this, I believe you have fiddled it up by using the bot = variable twice, in two different ways. The way I would do it is as following:

First, import our libraries and define the token:

import discord
from discord.ext import commands

TOKEN = "MyToken"

Next, we need to set up the bot variable, as so:

bot = commands.Bot(command_prefix='$', intents=discord.Intents.all()) # I usually add all intents, you can use discord.Intents.default if you like.

I add intents because Discord sometimes gets angry if you do not, so I like to make it a just in case backup.

Now, we create the command:

@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)

And lucky last, log into our bot:

bot.run(TOKEN)

Prior to our command, you can enter an on_ready function to verify the bot has logged in correctly:

@bot.event
async def on_ready():
    print(f"{bot.user} logged in successfully.")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.