I’m having trouble with a Discord bot I’m making. I followed a YouTube tutorial for a Massive DMs Bot, but it’s not working as expected. Here’s my code:
import discord
from discord.ext import commands
import random
import colorsys
bot = commands.Bot(command_prefix = '!')
@bot.event
def on_ready():
print(f'Bot is online as {bot.user.name}')
@bot.command()
@commands.has_permissions(kick_members=True)
def member_info(ctx, member: discord.Member):
color = discord.Color.from_hsv(random.random(), 1, 1)
embed = discord.Embed(title=f"{member.name} Info", color=color)
embed.add_field(name='Name', value=member.name)
embed.add_field(name='ID', value=member.id)
embed.add_field(name='Status', value=member.status)
embed.set_thumbnail(url=member.avatar.url)
await ctx.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
def broadcast(ctx, *, message: str):
for member in ctx.guild.members:
try:
await member.send(message)
await ctx.send(f'Message sent to {member.name}')
except Exception:
await ctx.send(f'Failed to send to {member.name}')
bot.run('YOUR_TOKEN_HERE')
I’ve also configured my Procfile and requirements.txt, yet the bot remains non-responsive. Could anyone suggest what might be causing this issue?
dunno if it helps, but try checkin ur discord bot’s intents in the dev portal. sometimes command issues come from async problems or misconfigured permissions. hope that fixes it!
I’ve run into similar issues before. From what I can see, your code looks generally fine, but there are a few things you might want to check:
First, make sure you’ve enabled the necessary intents in the Discord Developer Portal. For your bot to function properly, you’ll need to enable the ‘Server Members Intent’ and ‘Message Content Intent’.
Also, double-check that you’ve correctly replaced ‘YOUR_TOKEN_HERE’ with your actual bot token. It’s a common oversight that can cause the bot to appear unresponsive.
If those don’t solve it, try adding some error handling and logging to your code. This can help pinpoint where exactly the bot is failing. You might want to wrap your main bot code in a try-except block and log any exceptions that occur.
Lastly, ensure your bot has the correct permissions in your Discord server. It needs to be able to read messages, send messages, and manage messages at minimum for these commands to work.
Have you verified that your bot is actually connecting to Discord? Try adding some debug logging in your on_ready event to confirm it’s initializing properly. Also, ensure you’re using the correct bot token and that it hasn’t been compromised or regenerated recently.
Another thing to check is your command error handling. You might want to add a global error handler to catch and log any command exceptions. This can help identify issues that aren’t immediately apparent.
Lastly, consider the permissions your bot has on the server. Even with the code-level permissions you’ve set, if the bot’s role doesn’t have the necessary server permissions, the commands won’t work.
If none of these solve the issue, you might want to review Discord’s API documentation for any recent changes that could affect your bot’s functionality.