#Checking if message is something in a slash command?
1 messages · Page 1 of 1 (latest)
My code is far more complicated, and I don't want to share it, so I'll just use some example code because it doesn't work there either.
message.channel.contains("something") used to work well, but now it doesn't. Nothing happens, no errors in the terminal. I was forced to use slash commands and have been using it ever since.
Even something as simple as this doesn't work:
import discord
client = discord.Client()
@client.event
async def on_ready():
print(f"Logged in as {bot.user}")
@client.event
async def on_message(message):
if message.content == "Duck":
await message.channel.send("Goose")
So combining it with slash commands obviously doesn't work:
import discord
bot = discord.Bot()
@bot.event
async def on_ready():
print("Logged in as {bot.user}")
@bot.slash_command(guild_ids=[0123456789])
async def test(ctx):
if message.content == "Duck":
await ctx.respond("Goose")
Even tried combinations out of desperation like ctx.message (even if it isn't an attribute), ctx.content, or ctx.interaction.message, nothing happened. Enabling the Message intent in the Developer Portal and adding:
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Bot(intents=intents)
to the code didn't work. I need help.
You must now explicitly define the messages intent
On the portal
Have you done that? If not, kick, select, reinvite
i did
Ah I see the problem
Full disclosure, I do NOT know how to fix it, someone else can chime in
But I do see it
did you even tried to print the content as first debug step?
Your if message content is within the slash command. But there was no message. It was an interaction
and to that, yes
It only would work on a message context menu with the target message
Yup. If you placed that function within an event, it would work. Not within a slash command.
Also your slash command is missing name and description
except you do something crazy like fetch the last message in the executing channel or even make an int option like content of 5 messages before
and that
🤣
But yes, to Lalas point, I would put various print to console messages, to see exactly where it fails
duck
Goose

Goose
it's too easy in c#
I’m way too dumb for C#. Lmao
hahaha i have 13 years experience
😅
or > i had no friends, so i learned
import discord
client = discord.Client()
@client.event
async def on_ready():
print(f"Logged in as {bot.user}")
@client.event
async def on_message(message):
print(message.content)
if message.content == "Duck":
await message.channel.send("Goose")
Goose
Goose
Goose
fuck
@whole olive try this pls
i was doing something else, then started writing another dummy bot, this did print something
ok so it finds something
hmm
Client.MessageCreated += async (s, e) =>
{
if (e.Channel.Id == 992386142093713418 && e.Message.Content.ToLower().Contains("duck"))
await e.Message.RespondAsync("Goose");
};
as my code is, i would suggest you make the string lower and check for the contain then
dunno how to make it in python tho 😅
probably not, i'll have to rewrite like 60+ lines
i rewrote several lines and reduced it by about 40 lines, with the added benefit of it not working. i don't think this is possible without a command, which defeats the purpose of having to do all this rewriting
No, because messages and interactions are not the same
which is why i sent the "nvm"
It’s also important to note that messages.content is case sensitive
Which you might know already but figured I would throw it out there
by that, do you mean that what im typing as a command is case sensitive, or the actual messages.content in the code is case sensitive
not that im scared that i made a mistake, i already knew python is case sensitive
if message.content == "duck":
Duck would not trigger it
in that case you'd need to do:
if message.content.lower == "duck":
Then DUCK or Duck or any combo would trigger
To test whether or not it works, I would add a couple of lines to Lala's edit, so you have more visibility:
@client.event
async def on_message(message):
if message.content == "duck":
print(f'Success! {message.content} triggered!')
# Do things here
else:
print(f'Failure! {message.content} was not duck')
that way even if it fails, you can see on console what its actually comparing to your variable.
You hopefully see something such as :
Failure! Duck was not duck
Then you know its the lower problem.
no need to kick
interesting. I thought it only defined the intents upon invite. Good to know.
Yeah the new invite will update the scopes
Does your code work now or are you still having problems?
it is impossible to accomplish what i intend to, I'll just have to use slash commands without message.content
i have no choice
I got a bit lost what are you trying to do?
You want to see if a channel contains a message?
yeah, except that doesn't work for slash commands. the slash command does a while loop then i wanted a way to stop it without restarting the bot, but that isn't possible
stopping a while loop? Just use a counter.
then again, I still don't know what you're trying to accomplish. lol
You can use a counter with time ( seconds ) or with "attempts" but if we knew more details, we could help better.
You can use an async iterator over the channel's history
what im doing is someone triggering a command then it infinitely repeating until they feel like it should stop
idk, too little detail to go on here. I mean, based on this vague data, I'd say add something in there to check a json file as well, then your "admin" command changes that json file, effectively telling all other loops to end, but this is a shot in the dark considering the info you've provided.