-
The output displayed on my console, along with the corresponding code, is provided below. Despite implementing solutions from similar issues, I'm still encountering this problem.
@bot.event
async def on_message(message: discord.Message):
# Ensure the message is from a guild and not from the bump bot
if message.guild is not None and message.guild.id != GUILD_ID:
return
if message.author.bot and message.author.id == BUMP_REMINDER_ID:
print(message.content)
if "you can bump again!" in message.content.strip():
print("Passed")
try:
print("Before slash_commands")
# Retrieve all slash commands in the channel
commands = [command async for command in message.channel.slash_commands()]
print(f"Server bump initiated.\nCommands: {commands}")
for command in commands:
if command.name == '/bump': # 'bump' was also tested
print(f"Preparing to send: {command}")
await command(message.channel)
print("After slash_commands")
except Exception as e:
print(f"Error: {e}")
else:
print(f"{message.author} | {message.author.id}: {message.content}") EditI've done some more testing and unfortunately I can say that I'm still having this issue. Heres my code: @staticmethod
def traceback_maker(err: Exception, advance: bool = True) -> str:
_traceback = "".join(traceback.format_tb(err.__traceback__))
error = f"```py\n{_traceback}{type(err).__name__}: {err}\n```"
return error if advance else f"{type(err).__name__}: {err}"
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')
@bot.event
async def on_message(message: discord.Message):
# check if the message is from a guild and not from akiko
if message.guild is not None and message.guild.id != GUILD_ID:
return
if message.author.bot and message.author.id == BUMP_REMINDER_ID:
print(message.content)
if "you can bump again!" in message.content.strip():
print("Passed")
try:
print("Before slash_commands")
# Get all slash commands in the channel
commands = [command async for command in message.channel.slash_commands() if command.name == 'bump' and command.application_id == 947088344167366698]
if commands:
command = commands[0]
print(f"Was called to bump the server.\nCommand: {command}")
print(f"Going to send: {command}")
await command(message.channel)
print("After slash_commands")
except Exception as e:
print(f"Error: {traceback_maker(e, True)}")
else:
print(f"{message.author} | {message.author.id}: {message.content}")``` |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Okay i was able to fix it. I followed this other discussion. they suggested to use a different commit and that seems to have done it. Heres my code if any of you want a similar system. import asyncio
import random
import traceback
from typing import TYPE_CHECKING
import discord
from discord.ext import commands
from tokens import tokens
if TYPE_CHECKING:
pass
description = None
commands_cache = {}
bot = commands.Bot(
command_prefix="?!?!?!?!?!?!?",
description=description,
self_bot=True,
help_command=None,
)
TARGET_BOT_ID = # add your values here
TARGET_COMMAND_ID = # add your values here
TARGET_GUILD_ID = # add your values here
@staticmethod
def traceback_maker(err: Exception, advance: bool = True) -> str:
_traceback = "".join(traceback.format_tb(err.__traceback__))
error = f"```py\n{_traceback}{type(err).__name__}: {err}\n```"
return error if advance else f"{type(err).__name__}: {err}"
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
print("------")
@bot.event
async def on_message(message: discord.Message):
# check if the message is from a guild and not from the bot
if message.guild is not None and message.guild.id != TARGET_GUILD_ID:
return
if message.author.bot and message.author.id == TARGET_BOT_ID:
if "you can bump again!" in message.content.strip():
print("Passed")
try:
# Check if the commands are in the cache
if message.channel.id not in commands_cache:
# If not, fetch the commands and store them in the cache
commands_cache[message.channel.id] = await message.channel.application_commands()
all_commands = commands_cache[message.channel.id]
for command in all_commands:
if command.id == TARGET_COMMAND_ID:
print(f"Found the /bump command: {command}")
print(f"Going to send: {command}")
await asyncio.sleep(random.randint(10, 30))
await command(message.channel)
break # Exit the loop once the command is found and sent
except Exception as e:
print(f"Error: {traceback_maker(e, False)}")
for token in tokens:
bot.run(token.strip()) |
Beta Was this translation helpful? Give feedback.
Okay i was able to fix it. I followed this other discussion. they suggested to use a different commit and that seems to have done it. Heres my code if any of you want a similar system.