discord.py

What it really is @client.event? discord.py

久未见 提交于 2021-01-21 09:12:30
问题 A few days ago I became interested in programming discord bots a bit. In the syntax of these programs I noticed a lot of unintelligible issues that I can not find an answer to. That's why I am asking you for help in understanding them. All questions are based on this code: import discord import asyncio from discord.ext import commands botToken = '***' client = commands.Bot(command_prefix = '.') @client.event async def on_ready(): print('Bot is ready!') @client.event async def on_message

Custom Emoji's and Animated Emoji's not working [discord.py-rewrite]

不羁岁月 提交于 2021-01-20 11:34:20
问题 I recently built a simple command to test the format of custom emoji's and animated emoji's Here is what the command was @bot.command() async def say(ctx, *, text): await ctx.send("<:ono:521148278079881219> You said %s" % text) But the output message didn't send the custom emoji, instead it messaged :ono: You said hello(the text i messaged in chat) Any help will be appreciated. 回答1: You can use Client.get_emoji to get the Emoji object, then use that to build your string @bot.command() async

Custom Emoji's and Animated Emoji's not working [discord.py-rewrite]

大城市里の小女人 提交于 2021-01-20 11:34:06
问题 I recently built a simple command to test the format of custom emoji's and animated emoji's Here is what the command was @bot.command() async def say(ctx, *, text): await ctx.send("<:ono:521148278079881219> You said %s" % text) But the output message didn't send the custom emoji, instead it messaged :ono: You said hello(the text i messaged in chat) Any help will be appreciated. 回答1: You can use Client.get_emoji to get the Emoji object, then use that to build your string @bot.command() async

Custom Emoji's and Animated Emoji's not working [discord.py-rewrite]

点点圈 提交于 2021-01-20 11:33:55
问题 I recently built a simple command to test the format of custom emoji's and animated emoji's Here is what the command was @bot.command() async def say(ctx, *, text): await ctx.send("<:ono:521148278079881219> You said %s" % text) But the output message didn't send the custom emoji, instead it messaged :ono: You said hello(the text i messaged in chat) Any help will be appreciated. 回答1: You can use Client.get_emoji to get the Emoji object, then use that to build your string @bot.command() async

Get a Discord Role by Id

牧云@^-^@ 提交于 2021-01-20 04:47:10
问题 I'm making a Discord bot but just ran into a problem. I want to modify a role. A specific role. I know how to do that with edit_role , but I need to get the Role object to edit it. Now, that's the problem. How do I get a Role object by the role's id ? Or can I use the id in the Role argument ? 回答1: You can use discord.utils.get to loop through Guild.roles and get the one you're looking for: from discord.utils import get role_id = 123 role = get(guild.roles, id=role_id) 回答2: You can simply use

Sending a message to a specific user specified in the message, discord.py

橙三吉。 提交于 2021-01-07 04:26:31
问题 In my discord.py code I am trying to set up a simple send message to a user that the message author has specified. if message.content.startswith('!hello'): print("Hello DIRECT MESSAGE") msg = "Why hello there" print (message.author) await client.send_message(message.author, msg) if message.content.startswith('!poke'): print("Poke DIRECT MESSAGE") a = message.content[6:] print(a) msg = "Hi there" await client.send_message(a, msg) The !hello command works fine, but I do not know how to get the

how to make a bot that gives role when we join a particular voice channel and removes when left

﹥>﹥吖頭↗ 提交于 2021-01-07 02:49:31
问题 I am learning how to use discord.py and I want to make bot feature that give role when we join particular voice channel and removes the same role when user leaves the channel @client.event async def on_voice_state_update(): 回答1: on_voice_state_update gives you after and before arguments, here's how to check when a member joined and left a voice channel async def on_voice_state_update(member, before, after): if before.channel is None and after.channel is not None: # member joined a voice

How to make a NSFW command in discord.py?

℡╲_俬逩灬. 提交于 2021-01-07 02:27:46
问题 I am making a discord bot and I want a NSFW command in, so I used a command that's puts a random image of a NSFW subreddit, but I need help with the detection of a NSFW channel, so this command can't be used in channels that are not nsfw, and also send a message that says "You need to use this command in a nsfw channel!" Here's my command, but there's a error in the part of "else:" async def nsfw(ctx): if ctx.channel.is_nsfw(): embed = discord.Embed(title="test", description="test") async

How do I put multiple words in one argument discord.py

◇◆丶佛笑我妖孽 提交于 2021-01-07 01:19:31
问题 I am working on a bot that uses discord.py, and I want to have a command that lets you set the game the bot is playing, but I don't know how to make an argument that allows spaces. I have tried to make 2 arguments, but then if you want one word it will show up as an error. @client.command() async def game(gameplay): #do things I want the argument "gameplay" to have multiple words in it. Can someone please help? 回答1: @client.command() async def game(ctx, *args): # args contains all arguments

Discord.py how do I make a mute command?

孤者浪人 提交于 2021-01-06 07:52:56
问题 As the title says. I'm trying to figure out how to make a mute command using discord.py rewrite. I'm thinking that we need to have a "mute" role where the command used gives the user the "mute" role and for how long. How do I achieve this. I already have @bot.command() @commands.has_permissions(mute_members) async def mute(ctx, member:discord.Member): 回答1: The best way to do this would be to have a database setup in which you can add and remove users. Then you can use the on_message event and