- Discord.py: A Rephrased Guide to the Server Info Command
- Loop Command
- Server Info Command Discord.py
- 1. Indentation.
- 2. Read the documentation!
- 3. Unnecessary braces
- 4. [Not a mistake, but quick tip]
- Discord.py send_message usage
- Как получить информацию о дискорд-сервере только на том сервере где он используется?
Discord.py: A Rephrased Guide to the Server Info Command
If rectifying the indentation and eliminating the mentioned line does not solve the issue, then you will need to execute debug print statements sequentially, line by line, until you identify the problematic line. As a side note, I substituted the specified line with another one because it appeared to me that you intended to display information about the author rather than the guild on that line.
Loop Command
@bot.command(pass_context=True) async def repeat(ctx): voice = get(bot.voice_clients, guild=ctx.guild) if not voice.is_playing: return await ctx.send('Aucune musique joué !') await ctx.send("La répétition est activé \n Si vous voulez désactivé : n#stop") voice.loop = True await ctx.message.add_reaction('✅')
Why doesn’t the ‘play’ command repeat the music I play continuously?
I suggest giving itertools a try. Since I’m not well-versed in music bots, I’ll utilize ctx.send() temporarily.
from itertools import cycle import time import discord from discord.ext import commands, tasks client = commands.Bot(command_prefix='.') @commands.command() async def repeat(): music_list = cycle(["song1","song2"]) while True: time.sleep("length of song") await ctx.send(next(music_list))
Utilizing the cycle function is a delightful approach to implement loops that you should definitely consider experimenting with. The subsequent example effectively demonstrates the functionality of cycle, and perhaps this tutorial can offer some valuable insights.
Here is the link to a YouTube video: https://www.youtube.com/watch?v=RK8RzuUMYt8.
Python — Loop Command, Loop Command (discord.py) @bot.command (pass_context=True) async def repeat (ctx): voice = get (bot.voice_clients, guild=ctx.guild) if not …
Server Info Command Discord.py
@client.command() async def server(ctx): embed = discord.Embed(title = f" Info", description = "Information of this Server", color = discord.Colour.blue()) embed.add_field(name = '🆔Server ID', value = f"", inline = True) embed.add_field(name = '📆Created On', value = ctx.guild.created_at.strftime("%b %d %Y"), inline = True) embed.add_field(name = '👑Owner', value = f"", inline = True) embed.add_field(name = '👥Members', value = f' Members', inline = True) embed.add_field(name = '💬Channels', value = f' Text | Voice', inline = True) embed.add_field(name = '🌎Region', value = f'', inline = True) embed.set_thumbnail(url = ctx.guild.icon_url) embed.set_footer(text = "⭐ • Duo") embed.set_author(name = f'', url = embed.Empty, icon_url = ) await ctx.send(embed=embed)
After writing the Code, I noticed that everything appears to be functioning smoothly. Although there are no errors when I run the bot, the terminal remains empty. However, when I execute this specific command, it fails to produce a response. Additionally, there are no errors displayed in the terminal. I would greatly appreciate any assistance.
Upon initial observation, the indentation appears to be incorrect. Additionally, I am unfamiliar with the term url = embed.Empty .
In addition, I substituted the embed.set_author line with embed.set_author(name = f» icon_url = as it appeared to me that you intended to showcase information about the author instead of the guild.
@client.command() async def server(ctx): embed = discord.Embed(title = f" Info", description = "Information of this Server", color = discord.Colour.blue()) embed.add_field(name = '🆔Server ID', value = f"", inline = True) embed.add_field(name = '📆Created On', value = ctx.guild.created_at.strftime("%b %d %Y"), inline = True) embed.add_field(name = '👑Owner', value = f"", inline = True) embed.add_field(name = '👥Members', value = f' Members', inline = True) embed.add_field(name = '💬Channels', value = f' Text | Voice', inline = True) embed.add_field(name = '🌎Region', value = f'', inline = True) embed.set_thumbnail(url = ctx.guild.icon_url) embed.set_footer(text = "⭐ • Duo") embed.set_author(name = f'' icon_url = await ctx.send(embed=embed)
If resolving your indentation and eliminating url = embed.Empty doesn’t solve the problem, you will need to execute debug print statements line by line until you identify the problematic line.
There are few things wrong here.
1. Indentation.
It is essential to indent each line following the async def server(ctx): line to avoid repetition.
2. Read the documentation!
Upon reviewing the guild documentation, it becomes evident that the absence of guild.text_channel_count and guild.voice_channel_count requires an alternative approach. Instead, one must utilize ****(guild.text_channels) and ****(guild.voice_channels) .
3. Unnecessary braces
I don’t understand the purpose of having <> wrapped around icon_url = on the second last line. Therefore, please remove them.
Additionally, the inclusion of url=embed.Empty is redundant because it is the default value for embed.set_author() (refer to the provided link). Therefore, it should be removed.
4. [Not a mistake, but quick tip]
Using ctx.guild.owner alone will yield a Member object. However, when used within an f-string, it will provide a **** representation similar to or something idk . To display the owner of the server in the desired format, utilize ctx.guild.owner.mention . Please note that although it is within an embed, it will not ping the owner.
@client.command() async def server(ctx): embed = discord.Embed(title=f" Info", description="Information of this Server", color=discord.Colour.blue()) embed.add_field(name='🆔Server ID', value=f"", inline=True) embed.add_field(name='📆Created On', value=ctx.guild.created_at.strftime("%b %d %Y"), inline=True) embed.add_field(name='👑Owner', value=f"", inline=True) embed.add_field(name='👥Members', value=f' Members', inline=True) embed.add_field(name='💬Channels', value=f' <****(ctx.guild.text_channels)>Text | <****(ctx.guild.voice_channels)>Voice', inline=True) embed.add_field(name='🌎Region', value=f'', inline=True) embed.set_thumbnail(url=ctx.guild.icon_url) embed.set_footer(text="⭐ • Duo") embed.set_author(name=f'' icon_url=ctx.message.author.avatar_url await ctx.send(embed=embed)
Edit: I neglected to specify that I have slightly adjusted the formatting of your code to comply with PEP8 guidelines, such as removing spaces around the = in function calls, among other things.
Python — Server Info Command Discord.py, Server Info Command Discord.py. Ask Question Asked 6 months ago. I forgot to mention that I have formatted your code a bit to adhere to …
Discord.py send_message usage
I have begun a project aimed at expediting my mastery of python. My objective is to replicate a discord bot that I frequently employ, as I am already accustomed to its functionalities. Provided below is the code I am currently working with.
import discord from discord import User from discord.ext.commands import Bot import secrets pybot = Bot(command_prefix = "!") @pybot.event async def on_read(): print("Client logged in") @pybot.command() async def hello(*args): print(User.display_name) return await pybot.say("Hello, world!") @pybot.command() async def truck(*args): await pybot.send_message(message.user,'Watchout for that truck!') pybot.run(secrets.BOT_TOKEN)
The desired outcome is for a message to be sent to the user mentioned when the command » !truck » is typed, with the content being «Be cautious of the truck!
I’m getting the following error:
I have made attempts to search for examples of what I am attempting to accomplish, but I have not come across much or have not grasped what I should be doing. I hope this question is not a duplicate of a similar one.
I believe that using the *args syntax in your truck is no longer valid for the commands with discord.py .
@pybot.command(pass_context=True) async def truck(ctx): await pybot.send_message(ctx.message.user, 'Watchout for that truck!')
Explore the GitHub repository for Discord.py, which includes their sample codes.
Python — discord.py send_message usage, discord.py send_message usage. I’ve started working on a project to accelerate my learning of python. I’m trying to recreate a discord bot I use quite a …
Как получить информацию о дискорд-сервере только на том сервере где он используется?
У меня есть достаточно хороший бот, с достаточно большим перечнем команд. В этот раз я хочу настроить получение информации о только текущем сервере(объясню поподробней потом).
Я смог это сделать сам, но столкнулся с проблемой, что это была статистика за все сервера на котором находился бот. Мне нужно чтобы была команда отвечающая только за текущий сервер и не задевала другие. Я попробовал это воплотить в реальность, оно как я уже понял безуспешно.
Код:
async def server_info(ctx): members_count = 0 online = 0 offline = 0 idle = 0 dnd = 0 for member in ctx.guild: if member.status == discord.Status.online: online += 1 elif member.status == discord.Status.offline: offline += 1 elif member.status == discord.Status.idle: idle += 1 elif member.status == discord.Status.dnd: dnd += 1 members_count += 1
Ignoring exception in command server_info: Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\User\Discord\bots\database_test.py", line 156, in server_info for member in ctx.guild: TypeError: 'Guild' object is not iterable The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Guild' object is not iterable
По логике мне нужно было найти вместо ctx.guild, другой, который соответствовал моим требованиям. Но в документации и на просторах интернета я так и не смог найти решения именно к моему случаю. Я буду очень долго его совершенствовать, и ваша помощь будет очень кстати.