admin管理员组文章数量:1401640
I am writing a discord bot for the first time. I managed to debug a few things from the tutorial, like the fact that there is a new argument: intents, but when it came to creating commands I could not find any solution.
Basically my problem is that the commands are not working. Eventually I decided to give up and at least hope something simple would work (and not complicated commands) so I tried this:
import discord
from discord.ext import commands
TOKEN = '(my bot ID that is already added in my code)'
# Define the bot prefix
bot = commands.Bot(command_prefix='!',intents=discord.Intents.default())
@bot.event
async def on_ready():
print(f'The bot is ready have logged in as {bot.user}')
@botmand()
async def test(ctx):
await ctx.send('Test')
# Run the bot
bot.run(TOKEN)
What I expected to happen, is that when I did '!test' it would send "Test". But the bot did not respond with anything Then I tried doing a lot of things. Changing permissions to moderator, running it with F5 instead of python bot.py
, running it with python bot.py
instead of F5 (I usually do F5 but I still don't know if either of them work), etc.
So now I am stuck with a broken bot and the bot commands won't do what they are supposed to. A couple of websites I checked were for example things to change the bot to client, or questions about importing the right modules, adding all intents (that didn't even work, it just said there was an error in the module when I tried discord.Intents.all()
), etc. I also tried intents = discord.Intents.default()
intents.message_content = True
, as somebody suggested that, and that bugged the whole thing, causing a lot of errors mostly about the installed module.
How to resolve the issue?
I am writing a discord bot for the first time. I managed to debug a few things from the tutorial, like the fact that there is a new argument: intents, but when it came to creating commands I could not find any solution.
Basically my problem is that the commands are not working. Eventually I decided to give up and at least hope something simple would work (and not complicated commands) so I tried this:
import discord
from discord.ext import commands
TOKEN = '(my bot ID that is already added in my code)'
# Define the bot prefix
bot = commands.Bot(command_prefix='!',intents=discord.Intents.default())
@bot.event
async def on_ready():
print(f'The bot is ready have logged in as {bot.user}')
@botmand()
async def test(ctx):
await ctx.send('Test')
# Run the bot
bot.run(TOKEN)
What I expected to happen, is that when I did '!test' it would send "Test". But the bot did not respond with anything Then I tried doing a lot of things. Changing permissions to moderator, running it with F5 instead of python bot.py
, running it with python bot.py
instead of F5 (I usually do F5 but I still don't know if either of them work), etc.
So now I am stuck with a broken bot and the bot commands won't do what they are supposed to. A couple of websites I checked were for example things to change the bot to client, or questions about importing the right modules, adding all intents (that didn't even work, it just said there was an error in the module when I tried discord.Intents.all()
), etc. I also tried intents = discord.Intents.default()
intents.message_content = True
, as somebody suggested that, and that bugged the whole thing, causing a lot of errors mostly about the installed module.
How to resolve the issue?
Share Improve this question asked Mar 23 at 18:27 BomDevBomDev 12 bronze badges 3- Where are you running the command? Are you attempting to use it in a DM with the bot, or in a server? – keventhen4 Commented Mar 31 at 0:17
- In a server, does this only work in DM's? – BomDev Commented Apr 1 at 7:34
- As far as I know, only slash commands work in DMs (correct me if I'm wrong). – keventhen4 Commented Apr 1 at 22:56
1 Answer
Reset to default 0You need to enable the message_content intent in order to use text commands:
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
Also remember to enable the message content intent in the developer portal
- A primer to Gateway Intents
本文标签: Cant run discord commands made in pythonStack Overflow
版权声明:本文标题:Cant run discord commands made in python - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744273979a2598320.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论