I want the bot to react to its own message with the ✅ and ❎ emojis for a suggestion command. Here is the code. How do i do it?
import discord
from discord.ext import commands
class suggestions(commands.Cog):
def __init__(self, bot):
self.bot = bot
#commands.command(description = 'Add a suggestion for this community!')
async def suggest(self, ctx, *,suggestion):
await ctx.channel.purge(limit = 1)
channel = discord.utils.get(ctx.guild.text_channels, name = '💡│suggestions')
suggestEmbed = discord.Embed(colour = 0xFF0000)
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
suggestEmbed.add_field(name = 'New suggestion!', value = f'{suggestion}')
await channel.send(embed=suggestEmbed)
def setup(bot):
bot.add_cog(suggestions(bot))
Messageable.send returns a discord.Message object, you can then simply .add_reaction
message = await ctx.send(embed=suggestEmbed)
await message.add_reaction('✅')
await message.add_reaction('❌')
Note: You need the unicode of the emoji to react, to get it simply \:{emoji}:
Reference:
Messageable.send
Message.add_reaction
Me, I use this:
#bot.command()
async def suggestion(ctx, *, content: str):
title, description= content.split('/')
embed = discord.Embed(title=title, description=description, color=0x00ff40)
channel = bot.get_channel(insert the channel ID here)
vote = await channel.send(embed=embed)
await vote.add_reaction("✅")
await vote.add_reaction("❌")
await ctx.send("your suggestion has been send")
You can vote using the emojis, enjoy!
Related
I believe it goes something like this
#bot.command()
async def ticket(ctx, member, name):
await create_text_channel(name = f'{member}', subject = "test channel")
Please correct me if I am wrong
async def ticket(ctx, channelName):
guild = ctx.guild
embedTicket = nextcord.Embed(title = "Ticket", description="Sehr gut!")
if ctx.author.guild_permissions.manage_channels:
await guild.create_text_channel(name=f'{channelName}-ticket')
await ctx.send(embed=embedTicket)
This would be a way to do it.
I checked all codes what I can find but they don't work with my bot.What am I doing wrong?
They’re not much different and they all work, but not in my code. No mistakes in the cmd.
my friend can’t do it either. Bot has administrator privileges (I checked)
role = "NEWS"
#bot.event
async def on_member_join(member):
rank = discord.utils.get(member.guild.roles, name=role)
await member.add_roles(rank)
print(f"{member} was given the {rank} role.")
Second
#bot.event
async def on_member_join( member ):
role = discord.utils.get( member.guild.roles, id = 889869064997068810)
await member.add_roles( role )
Third
#bot.event
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, name='Unverified')
await member.add_roles(role)
All code without this auto role
import random
import json
import discord
import datetime
from lol import an
from zdar import answer_hello
from zdar import hello_words
from zdar import maternie
from zdar import answer_maternie
from discord.ext import commands
from config0 import settings
bot = commands.Bot(command_prefix= settings['prefix'])
bot.remove_command('help')
#bot.command()
async def clear(ctx, amount = 100):
await ctx.channel.purge( limit = amount )
#bot.command()
async def hello(ctx):
await ctx.send(f',{ctx.message.author.mention}!')
#bot.command()
async def cat(ctx):
await ctx.send(random.choice(an))
#bot.command()
async def time (ctx):
emb = discord.Embed(title = 'Титульник', colour = discord.Color.green(), url = 'https://www.timeserver.ru/cities/by/minsk')
emb.set_author(name = bot.user.name, icon_url = bot.user.avatar_url)
emb.set_footer ( text = ctx.author.name, icon_url= ctx.author.avatar_url)
emb.set_image( url= 'https://i.pinimg.com/originals/3f/82/40/3f8240fa1d16d0de6d4e7510b43b37ba.gif')
emb.set_thumbnail( url= 'https://static.wikia.nocookie.net/anime-characters-fight/images/9/90/Eugo_La_Raviaz_mg_main.png/revision/latest/scale-to-width-down/700?cb=20201114130423&path-prefix=ru')
now_date = datetime.datetime.now()
emb.add_field( name = 'Time', value='Time:{}'.format( now_date))
await ctx.send(embed = emb)
bot.run(settings['token'])
You have to specify the member intent to receive on_member_join events. You can do this while creating your bot object by adding an intent option:
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=settings['prefix'], intents=intents)
Note
If your bot is verified you require the SERVER MEMBERS INTENT which you can request on the bot page of your application.
So I'm trying to set up a log channel where it will post a message in that whenever someone gets kicked. At the moment I'm storing it in a json file, but i cant get it tow work. Does anyone have the code? Here's mine:
with open('log_channels.json', 'r') as f:
log_channels = json.load(f)
#client.command()
#commands.has_permissions(administrator = True)
async def modlog(ctx, channel = None):
log_channels[str(ctx.guild.id)] = channel.split()
with open('log_channels.json', 'w') as f:
json.dump(log_channels, f)
await ctx.send(f'Mod log set to {channel}')
#client.command()
#commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason = None):
await member.kick(reason = reason)
await ctx.send(embed=discord.Embed(title=f'{member} has been kicked.', color= 0xFF8633))
guild = ctx.guild
log_channels.get((guild.id) ('0'))
print (log_channels)
channel = client.get_channel(log_channels)
await channel.send(f"test")
Your error comes from this line:
log_channels.get((guild.id) ('0'))
And more precisely, from (guild.id) ('0'), which is equivalent to 123456789012345678('0') and is impossible.
What you probably meant to do is this:
#client.command()
#commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason = None):
await member.kick(reason = reason)
await ctx.send(embed=discord.Embed(title=f'{member} has been kicked.', color= 0xFF8633))
channel_id = log_channels.get(str(ctx.guild.id), '0')
channel = client.get_channel(channel_id)
await channel.send(f"test")
NB: json dict keys must be strings, so you need to get str(ctx.guild.id).
Also, if log_channel equals '0', channel will be None and channel.send() will raise an error.
What I would recommend doing is this:
#client.command()
#commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason = None):
await member.kick(reason = reason)
await ctx.send(embed=discord.Embed(title=f'{member} has been kicked.', color= 0xFF8633))
if str(ctx.guild.id) in logs_channels:
channel = client.get_channel(log_channels[str(ctx.guild.id)])
await channel.send(f"test")
else:
# Not mandatory, you can remove the else statement if you want
print('No log channel')
Here is what i have right now!
#client.command()
async def punch(ctx, *, response):
response = response.replace("(", "")
response = response.replace(")", "")
member = discord.utils.get(client.get_all_members(), id=response)
embed = discord.Embed(title=f":house_with_garden: Punched: {member} :punch:", color=discord.Colour.green())
await ctx.send(embed=embed)
And this is what happens: I want it to be Sauq#(then my tag)
You can use MemberConverter
#client.command()
async def punch(ctx, member: discord.Member): # By typehinting the member arg, `MemberConverter` will automatically convert it to a `discord.Member` instance
embed = discord.Embed(title=f":house_with_garden: Punched {member} :punch:", color=discord.Colour.green()) # If you want to mention the member: `member.mention`
await ctx.send(embed=embed)
The code I'm currently using was perfectly fine, but I really want to unban with ID because it is much easier for me.
Current command is in a Cog file:
import discord
from discord.ext import commands
class unban(commands.Cog):
def __init__(self, client):
self.client = client
#commands.command()
#commands.has_permissions(administrator=True)
async def unban(self, ctx, *, member : discord.Member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split("#")
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}\n', color=0x10940b)
unban.set_author(name="Moderating Action", icon_url=ctx.author.avatar_url)
await ctx.send(embed=unban)
return
def setup(client):
client.add_cog(unban(client))
How can I update this code to unban using the user ID instead?
async def unban(self, ctx, id: int) :
user = await client.fetch_user(id)
await ctx.guild.unban(user)
await ctx.send(f'{user} has been unbanned')
this should work for you, you can personalize even more, but that's just the main code you need.
Try
async def unban(self, ctx, *, member : discord.User):
await ctx.guild.unban(discord.Object(id = member.id))
unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}\n', color=0x10940b)
unban.set_author(name="Moderating Action", icon_url=ctx.author.avatar_url)
await ctx.send(embed=unban)