guild.members
содержит всех участников сервера, в том числе и вашего бота, который, в отличии от других участников сервера определен на основе объекта "клиента" бота и не имеет метода create_dm
.This should be rarely called, as this is done transparently for most people.
User.bot
:guild.roles[-1]
import typing
...
@commands.command()
async def ban(self, ctx, member: typing.Union[discord.Member, int], *, reason=None):
# https://discordpy.readthedocs.io/en/stable/ext/commands/commands.html#typing-union
if isinstance(member, int):
member = discord.Object(member)
try:
await ctx.guild.ban(member, reason=reason) # https://discordpy.readthedocs.io/en/stable/api.html#discord.Guild.ban
except NotFound:
await ctx.send(f"Не найдено пользователя с ID {member.id}")
@commands.command()
async def cmd(ctx):
if ctx.message.reference and isinstance(ctx.message.reference.resolved, discord.Message):
await ctx.send(ctx.message.reference.resolved.content)
else:
await ctx.send("You need to reply to message")
@commands.cooldown(rate, per, type=<BucketType.default: 0>)
@client.command()
@commands.cooldown(1, 60, commands.BucketType.user) # Один раз в 60 секунд на пользователя (глобально)
async def cmd(ctx, ...):
...
@client.listen("on_command_error")
async def cooldown_message(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"{ctx.command.qualified_name} можно использовать только {error.cooldown.rate} раз в {error.cooldown.per} секунд. Попробуйте через {error.retry_after} секунд.")
discord
, а не в discord.ext.commands
: https://discordpy.readthedocs.io/en/stable/api.htm...import discord # скорее всего такой импорт у вас уже есть
@command.error
async def command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f'Отсутствует требуемый аргумент: {error.param}')
if isinstance(error, commands.MissingPermissions):
await ctx.send(f'Недостаточно прав: {error.missing_perms}')
if isinstance(error, discord.HTTPException):
await ctx.send(f'Произошла ошибка при запросе: {error.status} ({error.text})')
ctx.channel.create_webhook
self
имеет смысл только в классе.@Bot.command()
- рискну предположить что класса там нет.self
из объявления функции:async def infouser(self, ctx, member: discord.Member = None):
bot.wait_for(...)
: https://discordpy.readthedocs.io/en/stable/ext/com... Traceback (most recent call last):
File "/home/fixator/Red-V3/lib/python3.8/site-packages/redbot/core/dev_commands.py", line 202, in _eval
result = await func()
File "<string>", line 13, in func
AttributeError: 'NoneType' object has no attribute 'edit'
discord.Message.edit
не возвращает ничего..edit
оригинального сообщения:load1=discord.Embed(title='Прогресс __0%__',color=2358184)
load2=discord.Embed(title='Прогресс __25%__',color=2358184)
load3=discord.Embed(title='Прогресс __50%__',color=2358184)
load4=discord.Embed(title='Прогресс __75%__',color=2358184)
load5=discord.Embed(title='Прогресс __100%__',color=2358184)
complete=discord.Embed(title='Загрузка завершена!',color=2358184)
msg=await ctx.send(embed=load1)
await asyncio.sleep(1)
await msg.edit(embed=load2)
await asyncio.sleep(1)
await msg.edit(embed=load3)
await asyncio.sleep(1)
await msg.edit(embed=load4)
await asyncio.sleep(1)
await msg.edit(embed=load5)
await asyncio.sleep(1)
await msg.edit(embed=complete)
get_user
ID в формате int
.author = bot.get_user(int(my_user_id))
await message_channel.send(f'{author.mention} - Welcome back!')
get_user
получает данные из кэша бота, и для его заполнения нужны intentsawait message_channel.send(f'<@{my_user_id}> - Welcome back!')
category
передаётся объект канала-категории.@bot.command()
async def cmdname(ctx):
category = bot.get_channel(788488692362607662) # ID категории
await category.create_voice_channel(ctx.author.name)
# ИЛИ
await ctx.guild.create_voice_channel(ctx.author.name, category = category)
# примеры использования, на данный момент, может измениться в будущем:
await ctx.send("my reply to your message", reference=discord.MessageReference(message_id=861988287927326702, channel_id=554470291913241936))
await ctx.send("my reply to your message", reference=discord.MessageReference.from_message(ctx.message))
await ctx.send("my reply to your message", reference=ctx.message.to_reference())
await ctx.reply("my reply to your message", mention_author=False)
await bot.http.request(
discord.http.Route(
"POST", "/channels/{channel_id}/messages", channel_id=ctx.channel.id
),
json={
"content": "test",
"message_reference": {
"guild_id": "453391932705247478",
"channel_id": "554470291913241936",
"message_id": "861988287927326702",
},
},
)