discord.py

Using discord.py, how would i check how much messages a user has sent in a specific channel

有些话、适合烂在心里 提交于 2021-01-29 07:52:41
问题 Using discord.py, how would i check how much messages a user has sent in a specific channel, and then for example every week, the bot will send a message for how much messages a user has sent for example, if i sent 30 messages in "#test" in a week, when the week ends it will send "@User has sent: 30 messages in #test". I'm not sure what to try. All I have setup is my bot with: @client.event async def on_message(message): no errors 回答1: Look at the discord.py documentation. You can use:

How to make give role on_message in discord.py?

馋奶兔 提交于 2021-01-29 07:21:05
问题 I want the bot to give role to users if they mentions three people in a specific channel , I want to do this with 2 channels and role for both channels are different, code: @client.event async def on_message(message): if message.channel.id == 724969989777522778: try: if len(message.mentions) >= 3: await message.add_reaction(emoji="<a:tick:748476262640779276>") role = discord.utils.get(message.guild.roles, name="CUSTOM 3pm") user = message.author await user.add_roles(role) #await.message.add

Disable discord.py command at certain times of day

南笙酒味 提交于 2021-01-29 06:44:52
问题 I have a tts bot that I want to either toggle on and off with a command, or be automatically turned of from 11pm - 7am when i'm sleeping. Is this possible? TTS Code: @client.command() async def tts(ctx, *, msg): print('{0} : {1}'.format(ctx.author, msg)) print('TTS started {}'.format(msg)) os.system('flite -t "{}"'.format(msg)) await ctx.send('TTS done.') 回答1: You can make a loop, that iterates every 24 hours that will change the enabled_tts variable to False, in the command, check if the

Python: Discord.py ERROR: Could not build wheels for multidict, yarl which use PEP 517 and cannot be installed directly

跟風遠走 提交于 2021-01-29 06:40:17
问题 So I recently have tried to install discord.py through cmd but its giving me an error no matter if I use pip3 py pip. It says i need to install visual studio 14 but i have visual studio 16 installed. I've uninstalled and reinstalled python 3.9.0 i've updated through 'pip install --upgrade pip" and it still gives me the same error. here is the error: Microsoft Windows [Version 10.0.18363.1139] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\rektb>pip Usage: pip <command> [options

Command cooldown in discord.py

我的未来我决定 提交于 2021-01-29 06:36:01
问题 I want commands for my discord bot to have cooldowns. I've tried other methods, but none of them seemed to work for what I have. @client.event async def on_message(message): if message.content == 'shear sheep': await message.channel.send('you sheared your sheep, gaining 1 wool.') #cooldown? 回答1: I would suggest using a variable to track weather the command has been used or before the cooldown. import time cooldown = True @client.event async def on_message(message): global cooldown if message

Keeeping the loop going until input (discord.py)

喜欢而已 提交于 2021-01-29 05:32:46
问题 I'm running a discord.py bot and I want to be able to send messages through the IDLE console. How can I do this without stopping the bot's other actions? I've checked out asyncio and found no way through. I'm looking for something like this: async def some_command(): #actions if input is given to the console: #another action I've already tried pygame with no results but I can also try any other suggestions with pygame. 回答1: You can use aioconsole. You can then create a background task that

Python discord.py ways to split output to bypass 2000 character limit

你说的曾经没有我的故事 提交于 2021-01-29 05:06:20
问题 I am attempting to output the contents of a text file to a discord channel via Discord. The issue I have is that there is a 2000 character limit. I have been able to bypass this by using the code below async def on_message(message): id = client.get_guild(73194604108722****) channels = ["football"] if str(message.channel) in channels: if message.content.find("!english") != -1: with open('/home/brendan/Desktop/englishfootball.txt', 'r') as file: await message.channel.send(file.read(2000).strip(

How do I get the channel a message was sent in?

老子叫甜甜 提交于 2021-01-28 21:36:29
问题 I have been trying and making and building some channel lockdown commands, but they all didn't work. So far, I only have a lockdown command which locks a specific, fixed channel (code down below). So could someone tell me how to make a lockdown command which locks the channel the command was sent in? @bot.command(aliases=['sd']) @commands.has_role('Admin') async def shutdown(ctx): """Shuts down #bank""" intro = bot.get_channel(768788764008251436) await intro.set_permissions(ctx.guild.default

How to get the age of someones account? Discord.py

眉间皱痕 提交于 2021-01-28 21:06:55
问题 To prevent new accounts from using a certain command, how could I get the age of a users account (or creation date) when they type a message. client.get_user(account_date) if account_date < 14: print('Your account must be older than 14 days to use this command') else: print('Your account can use this command') Any help is appreciated. 回答1: You can get a User object from either ctx with ctx.author or from a message with message.author . Then on the User object you can call created_at . So for

(discord.py) How do I get my bot to read DM's that are sent to it and either print them or send them to a specific channel

和自甴很熟 提交于 2021-01-28 19:28:28
问题 So I recently created a discord bot with various meme commands and moderating commands. I am relatively new to python but I understand the gist of it. I have already created a command that lets me(only me) DM a user through the bot. I now want to try and make the bot be able to read the messages that are sent back to it and send them to me, whether its printed in shell or sent to a specific channel/me I don't care, I just want to be able to see what is sent to it. I did some reading around