discord

Per server prefixs

被刻印的时光 ゝ 提交于 2019-11-30 22:02:28
I was wondering how I would go about allowing every server my bot is connected to, to set their own prefix. I am using the async version of dpy with Commands ext. I would assume you would store the prefix's and server name in a .json file, but I don't know how you would write them or check the file for them. Thanks You can do this with dynamic command prefixes. Write a function or coroutine that takes a Bot and a Message and outputs the appropriate prefix for that message. Assuming you had a JSON of server ids to prefixes: { "1234": "!", "5678": "?" } You can load that json into a dictionary

How do I use cogs with discord.py?

风格不统一 提交于 2019-11-30 21:03:46
问题 I have quite a large bot for discord written up. It has over 1000 lines of code. When I researched how to do it on youtube and here, nothing seems to be working. I was wondering if someone could explain how to use a cob properly, possibly with photo examples. I can show what code I have to help you understand what I want. An example would be that I want to have all of my mod commands in a separate file, just so its cleaner and more organized. so, how do I go about doing this? Here is an

Reaction pagination button forward and back python

偶尔善良 提交于 2019-11-30 20:43:52
问题 I'm trying to make a button / reaction to go back and forth between 3 different images, but the button is not coming back in the previous image, just advancing to the next one, could anyone help me? if message.content.startswith('!image'): msg1 = await Bot.send_file(message.channel, 'image1.png') toReact = ('⏩') for reaction in toReact: await Bot.add_reaction(msg1, reaction) def checkReaction(reaction, user): e = str(reaction.emoji) return e.startswith('⏩') res = await Bot.wait_for_reaction

Discord bot reading reactions

隐身守侯 提交于 2019-11-30 20:24:40
I need to implement some of the feature and one of the feature is implementing polls type feature. Can't use public discord bots due to some policies so we have to implement something on my own. Did some research yesterday and was able to make basic bot using python3 and commands api from discord.ext . Now what i need to figure out is: Read reactions added by a user to a message? Create a message with reactions (like bots which create reaction polls?) Pin a message? I believe from ctx i can get user tags (admin etc). Is there a better way to do so? Couldn't find anything helpful on Commands

Change user nickname with discord.js

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 19:50:49
I wonder if you can help (I search it and nothing...) I am learning how to work with discord.js node and I want to change my user nickname (not the username itself) My code is const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { console.log('I am ready!'); }); client.on('message', message => { if (message.content.includes('changeNick')) { client.setNickname({nick: message.content.replace('changeNick ', '')}); } }); client.login('token'); According to the Docs , You can only change a guild members nickname, so you need to get the member object

Discord money bot keeping user ID's in json file. When Bot restarts it creats a new (but same) ID for everyone

只谈情不闲聊 提交于 2019-11-30 09:41:25
问题 When this code runs it works getting the user ID from discord and putting they have 100 money in the json, but once you restart the bot you have to register again and it writes the same user ID in the json file thinking it's a new user when it is not. from discord.ext import commands import discord import json bot = commands.Bot('!') amounts = {} @bot.event async def on_ready(): global amounts try: with open('amounts.json') as f: amounts = json.load(f) except FileNotFoundError: print("Could

How to join a server?

孤人 提交于 2019-11-30 06:16:30
问题 I'm trying to setup a discord bot with python. I have a pre-existing discord server that I would like the bot to join, but I'm having a hard time doing so. import discord import asyncio import logging logging.basicConfig(level=logging.INFO) client = discord.Client() @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') print(client) @client.event async def on_message(message): print(message) if message.content.startswith('!test

Change user nickname with discord.js

跟風遠走 提交于 2019-11-30 04:50:44
问题 I wonder if you can help (I search it and nothing...) I am learning how to work with discord.js node and I want to change my user nickname (not the username itself) My code is const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { console.log('I am ready!'); }); client.on('message', message => { if (message.content.includes('changeNick')) { client.setNickname({nick: message.content.replace('changeNick ', '')}); } }); client.login('token'); 回答1:

Discord.py silence command

冷暖自知 提交于 2019-11-29 15:20:13
I have been asking loads of questions lately about discord.py and this is one of them. Sometimes there are those times when some people spam your discord server but kicking or banning them seems too harsh. I had the idea for a silence command which would delete every new message on a channel for a given amount of time. My code so far is: @BSL.command(pass_context = True) async def silence(ctx, lenghth = None): if ctx.message.author.server_permissions.administrator or ctx.message.author.id == ownerID: global silentMode global silentChannel silentChannel = ctx.message.channel silentMode = True

How to use local file as thumbnail in DiscordJS embedded message?

荒凉一梦 提交于 2019-11-29 14:55:42
Is it possible to use a local file as a thumbnail for an embedded message with DiscordJs? "thumbnail": { "url": "../img/025.png" }, This doesn't seem to work. (node:34721) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): DiscordAPIError: Invalid Form Body embed.thumbnail.url: Not a well formed URL. Normal URL's do work however. Hedva I've already found an answer. Linking to the proper url of the file wasn't an option for me, because some images were generated. You can attach an image to the message, and use this attachment as thumbnail. Most basic example: const