discord.py

Discord.py: Trying to do an action depending on user reaction

不问归期 提交于 2021-01-28 05:21:48
问题 This is the code: import asyncio import discord from discord.ext import commands client = commands.Bot(command_prefix = ".") Token="" @client.command() async def react(ctx): message = await ctx.send("Test") await message.add_reaction("<💯>") await message.add_reaction("<👍>") user=ctx.message.author def check(reaction, user): user == ctx.message.author and str(message.emoji) == '💯' try: reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) except asyncio.TimeoutError

Is it possible to put an async function as a callable argument?

老子叫甜甜 提交于 2021-01-28 05:10:08
问题 I'm coding a music bot for my server, and I need to disconnect (a coroutine) when the queue is exhausted. So I use a try: except block to handle that, however, when using VoiceClient.play , is it possible to put an asynchronous function as the after parameter? Just using after=function does not work and would raise function was not awaited, but using after=await function shows TypeError: object function can't be used in 'await' expression Is there any way to call an async function from play?

How can I check for a reaction for my help command in d.py which checks the that author should be the only one that can use it

社会主义新天地 提交于 2021-01-28 05:09:33
问题 await message.add_reaction('📜') await message.add_reaction('🔧') await message.add_reaction('🔨') await message.add_reaction('🔥') message = await client.wait_for('on_reaction_add', timeout= 10, check=lambda message: message.author == ctx.author) if message.reaction_add == '📜': await ctx.send("You reacted!") Im making a command to use the help page and it edits the pre-existing help message to the category the user chooses that corresponds to the emoji they reacted for. I have used a way that

How do I get the bot to post Spoiler Images in discord.py?

耗尽温柔 提交于 2021-01-28 05:06:53
问题 I started with discord.py a month or two ago, so this might just be really simple. My code is: attachment_url = ctx.message.attachments[0].url await archiver.send(attachment_url) "archiver" is the channel I'm sending it in. How do I make it send with a spoiler tag? I looked through the docs but they're not helpful. Thanks. 回答1: In order for you to upload an image as a spoiler, you need to add SPOILER_ to the start of the image name, you can do that with: file = ctx.message.attachments[0] file

How to get message by id discord.py

房东的猫 提交于 2021-01-28 03:20:22
问题 I'm wondering how to get a message by its message id. I have tried discord.fetch_message(id) and discord.get_message(id) , but both raise: Command raised an exception: AttributeError: module 'discord' has no attribute 'fetch_message'/'get_message' 回答1: When getting a message, you're going to need an abc.Messageable object - essentially an object where you can send a message in, for example a text channel, a DM etc. Example: @bot.command() async def getmsg(ctx, msgID: int): # yes, you can do

ModuleNotFoundError: No module named 'cogs'

百般思念 提交于 2021-01-27 22:00:09
问题 I wrote a discord bot that uses cogs. Here's my code for loading in each extension/cog: import discord import os from discord.ext import commands client = commands.Bot(command_prefix= '.') @client.command() async def load(ctx, extension): client.load_extension(f'cogs.{extension}') @client.command() async def unload(ctx, extension): client.unload_extension(f'cogs.{extension}') @client.command() async def reload(ctx, extension): client.unload_extension(f'cogs.{extension}') client.load_extension

Add reaction to a message (discord.py)

南楼画角 提交于 2021-01-27 19:34:28
问题 I want to add a reaction to a message that gets send in one channel. I get the error code: discord.errors.InvalidArgument: emoji argument must be str, Emoji, or Reaction not NoneType. Here is my code: client = discord.Client() if message.channel.id == 737668230012862514: emoji = client.get_emoji(310177266011340803) await message.add_reaction(emoji) 回答1: The line: emoji argument must be str, Emoji, or Reaction not NoneType indicates that the emoji was set to None , meaning that the client

Discord.py SSLCertVerificationError

倖福魔咒の 提交于 2021-01-27 14:15:53
问题 I have been working on a bot and last night it was working just fine operating as needed but this morning when I opened the bot in my terminal I got this following error: Traceback (most recent call last): File "d:/Documents/Bots/DS BOT/bot.py", line 58, in <module> bot.run(token, bot=False) File "C:\Python38\lib\site-packages\discord\client.py", line 640, in run return future.result() File "C:\Python38\lib\site-packages\discord\client.py", line 621, in runner await self.start(*args, **kwargs

Is there an update on Typing.Optional on python 3.9 or am I doing something wrong?

大城市里の小女人 提交于 2021-01-27 13:41:26
问题 While I was coding for help command for my bot in Discord.py, This function was not working as I expected. def syntax(command): cmd_and_aliases = '|'.join([str(command), *command.aliases]) params = [] for key, value in command.params.items(): if key not in ('self', 'ctx'): params.append(f'[{key}]' if 'NoneType' in str(value) else f'<{key}>') params = ' '.join(params) return f'`{cmd_and_aliases} {params}`' What I wanted for this function was, returning and printing names and aliases to call up

I'm getting a certain error on my TEMPMUTE command

末鹿安然 提交于 2021-01-27 13:02:52
问题 I have made a tempmute code or we can say I found one on stackoverflow. I copied the code but it doesn't seem to work. If anyone of you now and can help me thanks! The code is; @commands.has_permissions(kick_members=True) async def tempmute(ctx, member: discord.Member, time=0, reason=None): if not member or time == 0: return elif reason == None: reason = 'No reason' try: if time_list[2] == "s": time_in_s = int(time_list[1]) if time_list[2] == "min": time_in_s = int(time_list[1]) * 60 if time