discord.py-rewrite

How to make a loop in discord.py rewrite?

微笑、不失礼 提交于 2019-12-25 00:14:43
问题 The bot must do something every 60 seconds. I tried to use create_task, but it does not work(the bot started but nothing happened). How can this be implemented? 回答1: client.loop.create_task should still work fine with the rewrite version. Example of a background task in the rewrite version can be found here. from discord.ext import commands import asyncio client = commands.Bot(command_prefix='!') async def background_task(): await client.wait_until_ready() counter = 0 channel = client.get

How do you assign roles with the discord.py rewrite?

一笑奈何 提交于 2019-12-24 10:43:02
问题 I am creating a discord bot using discord.py rewrite and am hosting iton repl.it. I am trying to add assignment of roles, but I get an error everytime I try to add it I'be looked around stack overflow and have been unable to find a solution to adding roles. I've also looked through the documentation, but that just made me more confused. import discord.utils @client.command() async def role(ctx, * role): user = ctx.message.author role = discord.utils.get(user.guild.roles, name=f"{role}") await

Print friends-list to console Discord.py

ε祈祈猫儿з 提交于 2019-12-20 06:45:13
问题 How would I go about printing to console a list of all my friends? I'm hoping to be able to achieve this with the Discord.py library, hopefully someone here knows. I currently get the error: for user in discord.ClientUser.friends: TypeError: 'property' object is not iterable Program: token = "" prefix = "::" import discord import asyncio import codecs import sys import io from discord.ext import commands from discord.ext.commands import Bot print ("waiting") bot = commands.Bot(command_prefix

A presence/activity set command?

左心房为你撑大大i 提交于 2019-12-13 23:09:12
问题 So, I was wondering if there could be a command I could write that allows me to set the bots presence and activity (ex. ~~set presence idle or ~~set activity watching "people typing ~~help") or something like that. Unrelated question: How do I set commands to be used by me only? I haven't found any example code for this, and i'm a beginner. 回答1: You can use the is_owner check to ensure that you are the only person who can invoke a command. To change the presence or status of the bot, use the

Run an async function when youtube-dl finishes downloading (python)

怎甘沉沦 提交于 2019-12-12 07:18:11
问题 I've been writing a music bot for python using the discord.py rewrite. It downloads videos via youtube-dl and plays them back in a voice chat. I've been working hard on a music extension, and recently realized I've completely overlooked something. The progress hooks option of youtube-dl is synchronous, while discord.py is async. youtube-dl spawns a subprocess when downloading a video rather than running it on the current thread, so it does not hang the program. The function I need to run on

How to how to convert username to discord ID?

让人想犯罪 __ 提交于 2019-12-11 18:25:52
问题 I have a simple questions about discord. I am trying to create an economy system, and it works well, but I want to customize it a bit. I am using this person's module: https://github.com/Rapptz/discord.py How do I convert a username to a discord ID. For example if I have a discord "command" to allow people to gift each other money, like: james#0243 types !give 100 bob#9413 . How can I convert bob#9413 to a discord id like 58492482649273613 because in my database, I have people's users stored

Get message content from reply in DM

烂漫一生 提交于 2019-12-11 18:04:09
问题 I started making a little discord bot to give a key to people who request it. However, requirements changed and now I need to get a valid email from people who want one. I'm not sure how to get a reply in a DM. I saw Discord.py get message from DM But I don't really have client.get_user_info() or something? bot = commands.Bot(command_prefix='!') @bot.command(pass_context =True, no_pm=True, name='key', help="I give you a key. you're welcome", ) async def key_giver(ctx): commandTime = str

Having trouble making a discord bot that direct messages @mentioned user

一世执手 提交于 2019-12-11 17:52:24
问题 trying to create a command for my bot where you can type /ping @user, and it then dm's mentioned user, as well as replies in chat with 'pong' heres what i have so far: async def cmd_ping(self, author, user_mentions): if not user_mentions: raise exceptions.CommandError("No users listed.", expire_in=20) else: usr = user_mentions[0] await self.safe_send_message(mention_user, "`pong!`") return Response(self.str.get('mentioned-user', "***{0}*** `pong`").format(usr.name,)) without await self.safe

Adding a check issue

自古美人都是妖i 提交于 2019-12-11 16:18:43
问题 Hi I'm trying to check if only the specific user has typed yes or no then apply the role. At the moment if a mentionable role is added it will first return a message asking the user whether they want to add this role. However this line causes a conflict say when another user types yes it it applies the original user the role. This is not the result I expected. So how would I go about adding a check? Here is the code I'm working with and the line where I'm having the issue. if msg is None or

Send a pm from discord.py rewrite

假如想象 提交于 2019-12-11 10:48:05
问题 I'm trying to figure out how to send a pm from a discord.py rewrite bot. I can't do ctx.author.send("context") because it messaging someone other than the author of the message. here's the code that I have so far when I'm searching for a user it always comes with the value of NONE @bot.command() async def spam(ctx, author, message, amount): print(author) print(ctx.author) victim = bot.get_user(author) print(victim) if not (victim == None): for i in range(int(amount)): await victim.send