When signing a player to a team, bot doesn't print a roster count, and just says 0.
#bengals.event
#commands.has_any_role('Franchise Owner', 'General Manager', 'Head Coach', 'Assistant Coach')
async def on_message(message, *, user:discord.Member=None):
if '<:Cincinnati_Bengals:801216801425457153> sign' in message.content:
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
guild = bengals.get_guild(801206329049612288)
bengalrole = discord.utils.get(guild.roles, name="Cincinnati Bengals")
freerole = discord.utils.get(guild.roles, name="✨ League Membership")
rostercount = len(bengalrole.members)
embedsigned = discord.Embed(title="KFG Transaction Complete", description=signee+" has been signed to the <:Cincinnati_Bengals:801216801425457153> Cincinnati Bengals.", color = discord.Color.green())
embedsigned.add_field(name=f'<:Cincinnati_Bengals:801216801425457153> Cincinnati Bengals new roster count is **{rostercount}**.', value="KFG Transaction")
await message.channel.send(embed=embedsigned)
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(bengalrole)
await guys.remove_roles(freerole)
Related
I have the link part down but it gives me a 400 Bad Request (error code: 50006): Cannot send an empty message error when i send a link the main problem is that if i try any other methods of writing this code for example i copied some code that deletes all of the messages sent in a chat but it still gives me the same error.
import discord
import responses
async def send_message(message, user_message, is_private):
try:
response = responses.get_response(user_message)
await message.author.send(response) if is_private else await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
TOKEN = ''
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
client = discord.Client(intents=intents)
#client.event
async def on_ready():
print(f'{client.user} is now running!')
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.author.id == 0000000000000 and message.startswith("https"):
await message.delete()
# can return here as we deleted message - no need to process anything else
return
username = message.author.name
user_message = message.content
channel = message.channel.name
print(f'{username} said: "{user_message}" ({channel})')
if user_message[0] == '?':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
#client.event
async def on_message(message):
if message.author == client.user:
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
print(f'{username} said: "{user_message}" ({channel})')
if user_message[0] == '?':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
client.run('')
Turning my comments into an answer;
Firstly, you need to enable the message_content intent to be able to see message content. You will need to enable the message_content Privileged intent in the Discord developer portal as well.
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
client = discord.Client(intents=intents)
Then, there should only be one on_message event. But we can merge them.
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.author.id == 0000000000000 and message.startswith("https"):
await message.delete()
# can return here as we deleted message - no need to process anything else
return
username = message.author.name
user_message = message.content
channel = message.channel.name
print(f'{username} said: "{user_message}" ({channel})')
if user_message[0] == '?':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
I also changed the user ID to an int - as message.author.id is an int. And changed stop of the str() calls to using the name properties as well.
Is it possible to change the position of an embed field in discord.py?
Here is my more detailed problem:
I have an embed, but I have to make it modular, which means that with a command we can either add a field or delete one. The delete command works and the add command works, but now I need to be able to change the position of the field to be the same as the position of the role (because each field corresponds to a role).
How can I do that?
We can't edit embed field's position, but we can try to add every fields in the good ordor so we don't have to edit the field's position !
Here are my codes (working):
import asyncio
import discord
from discord.ext import commands
from datetime import datetime
intents = discord.Intents.all()
bot = commands.Bot(command_prefix = "!1789", help_command = None, intents=intents)
async def get_hour():
now = ""
now = datetime.now()
hour = now.strftime("%H:%M")
return hour
async def role_members_mention(role: discord.Role, emoji):
role_str = ""
if len(role.members):
for member in role.members:
role_str += f"**|** {emoji} **➜** {member.mention}\n"
role_str[:-1]
return role_str
async def soon(role, emoji, max):
soon = f"**|** {emoji} **➜ Soon**\n" * (int(max[role.name].replace("/", "")) - len(role.members))
soon[:-1]
return soon
async def get_all_roles():
guild = bot.get_guild(966749409314504774)
global ceo_aceo_roles_dict
ceo_aceo_roles_dict = {}
ceo = discord.utils.get(guild.roles, id = 966749523949023262)
aceo = discord.utils.get(guild.roles, id = 992137775883243530)
global all_roles_dict
all_roles_dict = {}
all_roles_dict[ceo.position] = ceo
all_roles_dict[aceo.position] = aceo
ceo_aceo_roles_dict[ceo.position] = ceo
ceo_aceo_roles_dict[aceo.position] = aceo
async def update_effective():
ceo_aceo = ""
embed = discord.Embed(title = "**E͟͟͟F͟͟͟F͟͟͟E͟͟͟C͟͟͟T͟͟͟I͟͟͟F͟͟͟ S͟͟͟T͟͟͟A͟͟͟F͟͟͟F͟͟͟**. <:3446blurplecertifiedmoderator:1001403463214825542>", description = "", color = 0x000000)
max = {}
total = {}
effectif_staff_emojis = ["<:adcrown:1001400557073866762>", "<:bluesettings:1001472768161894532>", "<:diplome:1001472522811883621>", "<:5961blurpleemployee:1001403806828994570>"]
roles_staff_emojis = ["<:5961blurpleemployee:1001403806828994570>", "<:Dev:1001412860091580487>", "<:direction:1001476149051924591>", "<:bluevoicechannel:1001473637091659836", "<:direction:1001476149051924591>", "<:spideyn7:996331019735158864>", "<:logo_twitch:1005196891010629702>"]
all_roles = sorted(all_roles_dict)
ceo_aceo_roles = sorted(ceo_aceo_roles_dict)
all_roles.reverse()
ceo_aceo_roles.reverse()
x = -1
for role in all_roles:
x += 1
all_roles[x] = all_roles_dict[role]
x = -1
for role in ceo_aceo_roles:
x += 1
ceo_aceo_roles[x] = ceo_aceo_roles_dict[role]
for role in all_roles:
number = 0
for car in role.name:
if car == "":
number += 1
max[role.name] = "/" + str(number)
if len(role.members) >= int(max[role.name].replace("/", "")):
total[role.name] = f"🔒 **{str(len(role.members))} {max[role.name]}**"
else:
total[role.name] = f"🔓 **{str(len(role.members))} {max[role.name]}**"
message = await (await get_effective_staff_channel()).fetch_message(1059250505689337998)
for role in ceo_aceo_roles:
ceo_aceo += f"{role.mention} {total[role.name]}\n{await role_members_mention(role, effectif_staff_emojis[0])}{await soon(role, effectif_staff_emojis[0], max)}\n\n"
embed.add_field(name = "**C.E.O & A.C.E.O** <:adcrown:1001400557073866762>", value = ceo_aceo, inline = False)
embed.set_thumbnail(url = "https://media.discordapp.net/attachments/1001404772496187392/1059246720669733014/Picsart_22-10-19_21-20-35-971.jpg?width=1326&height=529")
embed.set_image(url = "https://media.discordapp.net/attachments/1001404772496187392/1059246720875241542/Picsart_22-10-13_21-14-41-363.jpg?width=618&height=618")
await message.edit(embed = embed)
async def delete_messages(ctx, number_of_message_to_delete = 1, time_to_wait = 0):
await asyncio.sleep(time_to_wait)
await ctx.channel.purge(limit=number_of_message_to_delete)
#bot.event
async def on_ready():
print(f"[{await get_hour()}] Ready !\n Username: {bot.user.name}\n----------------------------------------------------")
await get_all_roles()
await update_effective()
while True:
await asyncio.sleep(600)
await update_effective()
#bot.command()
#commands.has_permissions(administrator = True)
async def addeffectifstaff(ctx, role: discord.Role, number = 1):
await delete_messages(ctx)
role = discord.utils.get(ctx.guild.roles, id = role.id)
if role in all_roles_dict.values():
await ctx.send("Désolé mais ce rôle est déjà dans l'effectif.")
else:
ceo_aceo_roles_dict[role.position] = role
all_roles_dict[role.position] = role
await update_effective()
await ctx.send(f"Bien ! Le rôle {role.name} a été ajouté à l'effectif !")
await delete_messages(ctx, 1, 3)
print(f'[{await get_hour()}] {ctx.author.name} used the command "addeffectifstaff" to make me add the role "{role.name}" to the effective message.')
#bot.command()
#commands.has_permissions(administrator = True)
async def deleffectif(ctx, role: discord.Role):
await delete_messages(ctx)
role = discord.utils.get(ctx.guild.roles, id = role.id)
if not role in all_roles_dict.values():
await ctx.send("Désolé mais ce rôle n'est déjà pas dans l'effectif.")
else:
ceo_aceo_roles_dict.pop(role.position)
all_roles_dict.pop(role.position)
await update_effective()
await ctx.send(f"Bien ! Le rôle {role.name} a été supprimé de l'effectif !")
await delete_messages(ctx, 1, 3)
print(f'[{await get_hour()}] {ctx.author.name} used the command "deleffectif" to make me remove the role "{role.name}" to the effective message.')
bot.run(token)
Tried everything I found here. No mistakes shown, unban just not working. discord.py 2.0.1, Python 3.10
Ban is working fine, but when I want to unban it's doing nothing. Nothing on console, nothing happening
#client.command()
#commands.has_permissions(ban_members = True)
#commands.has_permissions(administrator = True)
async def ban(ctx, member : discord.Member, *, reason = None):
await member.ban(reason = reason)
#unban
#client.command()
#commands.has_permissions(administrator = True)
async def unban(ctx, *, 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)
await ctx.send(f'Unbanned {user.mention}')
return'
In the version of discord.py you're using you must not use await for ctx.guild.bans() and you must also add an async at for ban_entry in banned_users:.
You also need to remove your ' after the return on the last line
Example:
#client.command()
#commands.has_permissions(administrator = True)
async def unban(ctx: commands.Context, *, member):
banned_users = ctx.guild.bans()
member_name, member_discriminator = member.split("#")
async for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
return
So im currently making a discord bot that give a specific role to who ever react to the message i encountered some problems i can't fix my self
#client.event
async def on_ready():
Channel = client.get_channel('904620745462804520')
Text= "React to get Verified!"
Moji = await client.send_message(Channel, Text)
await client.add_reaction(Moji, emoji='✅')
#client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('904620745462804520')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "✅":
Role = discord.utils.get(user.server.roles, name="Verified")
await client.add_roles(user, Role)
Please, read documentation carefully
#client.event
async def on_ready():
Channel = client.get_channel('904620745462804520')
Text = "React to get Verified!"
Moji = await Channel.send(Text)
await Moji.add_reaction(emoji='✅')
#client.event
async def on_reaction_add(reaction, user):
if reaction.message.channel.id != '904620745462804520' or user == client.user:
return
if reaction.emoji == "✅":
guild = await client.fetch_guild('GUILD_ID_HERE')
Role = discord.utils.get(guild.roles, name="Verified")
await user.add_roles(Role)
So basicly the person is trying to guess whats the name of the anime! What I want it to do is to ingore the case sentativity! How can I do that? Here is the code:
#client.command()
async def work(ctx):
await open_account(ctx.author)
users = await get_bank_data()
user = ctx.author
def check(m):
return m.author.id == ctx.author.id
Question1 = 'https://upload.wikimedia.org/wikipedia/en/thumb/d/dc/DARLING_in_the_FRANXX%2C_second_key_visual.jpg/220px-DARLING_in_the_FRANXX%2C_second_key_visual.jpg'
Question2 = 'http://www.j1studios.com/wordpress/wp-content/uploads/Trinity-Seven-Header-001-20160707.jpg'
Question3 = 'https://www.animenewsnetwork.com/hotlink/images/encyc/A18170-2511174083.1466822675.jpg'
Question4 = 'https://www.animenewsnetwork.com/hotlink/images/encyc/A16344-911899268.1425205899.jpg'
Question5 = 'https://www.theanimedaily.com/wp-content/uploads/2020/06/20061004422210.jpg'
Question6 = 'https://th.bing.com/th/id/OIP.zvtbvP4JZNrrlAKPnclMpwHaEK?pid=Api&rs=1&adlt=strict'
Question7 = 'https://mangathrill.com/wp-content/uploads/2020/01/pjimage-1-4.jpg'
Question8 = 'https://th.bing.com/th/id/OIP.xV_2srfdOhEre9Vua-u6zAHaFb?pid=Api&rs=1&adlt=strict'
Question9 = 'https://img1.looper.com/img/gallery/the-untold-truth-of-hunter-x-hunter/intro-1591800144.jpg'
Question10 = 'https://i1.wp.com/static.anidub.com/blog/2014/09/Seirei-Tsukai-no-Blade-Dance.jpg'
questionlist = [Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10]
question = random.choice(questionlist)
await ctx.send("What is the title name of this anime?")
await asyncio.sleep(1)
await ctx.send(question)
msg = await client.wait_for('message', check=check)
await msg.lower()
if question == Question1:
if msg.content == "darling in the franxx":
earnings = random.randrange(300, 500)
await ctx.send(f"You did good! You got an earning of **{earnings}** coins!")
else:
earnings = random.randrange(0, 200)
await ctx.send(f"Did you even try? You got **{earnings}** coins!")
msg = await client.wait_for('message', check=check) returns you the discord.Message class. And discord.Message has no attribute lower(). But it has content, content returns the string value of the message.
And also await msg.lower() is a weird usage, it's not a coroutine so you can't await it.
So you can simply do:
msg = await client.wait_for('message', check=check)
msg_content = msg.content.lower()
if question == Question1:
if msg_content == "darling in the franxx":
earnings = random.randrange(300, 500)
await ctx.send(f"You did good! You got an earning of **{earnings}** coins!")
else:
earnings = random.randrange(0, 200)
await ctx.send(f"Did you even try? You got **{earnings}** coins!")
And also, I suggest you to put questions and question list out of the command, it becomes more optimized.