discord.py (rewrite) How can I narrow a commands use ability to a single channel?

Jw Bowen

I'm trying to make this code work only in a specific channel. It just sends a ton of errors when I try to do the command in the right channel. Ill add my imports if you want to test it. Last time I tried to ask this question it got denied. I still don't know what to do and just need a little help as i'm new to coding a discord bot.

import discord
from discord.ext import commands, tasks
import os
import random
import asyncio
from asyncio import gather    
        
client = commands.Bot(command_prefix='.')
        
@client.command()
    async def car(ctx):
            pictures = [
            'https://car-images.bauersecure.com/pagefiles/78294/la_auto_show_11.jpg',
            'http://www.azstreetcustom.com/uploads/2/7/8/9/2789892/az-street-custom-gt40-2_orig.jpg',
            'http://tenwheel.com/imgs/a/b/l/t/z/1967_firebird_1968_69_70_2000_camaro_blended_custom_supercharged_street_car_1_lgw.jpg',
            'https://rthirtytwotaka.files.wordpress.com/2013/06/dsc_0019.jpg',
            'http://speedhunters-wp-production.s3.amazonaws.com/wp-content/uploads/2008/06/fluke27.jpg',
            'https://i.ytimg.com/vi/pCt0KXC1tng/maxresdefault.jpg',
            'https://i2.wp.com/www.tunedinternational.com/featurecars/dorift/02.jpg',
            'http://i.imgur.com/nEbyV82.jpg',
            'https://cdn.hiconsumption.com/wp-content/uploads/2019/02/Affordable-Vintage-Japanese-Cars-0-Hero-1087x725.jpg',
            'http://speedhunters-wp-production.s3.amazonaws.com/wp-content/uploads/2012/04/IMG_0268.jpg',
            'https://i.ytimg.com/vi/Y-moGXK2zLk/maxresdefault.jpg',
            'https://www.topgear.com/sites/default/files/images/big-read/carousel/2016/03/568cd4ab437c6557c583a6f4a4feb6d1/3carguyscarouselmarch2016.jpg'
            ]
            channel = discord.utils.get()
            if channel == 705161333972140072:
                await ctx.channel.purge(limit=1)
                await ctx.send(f'{random.choice(pictures)}')
    
client.run('token')
Black Thunder

You need a few changes in the command function:

  1. Fix indentation
  2. Use ctx.channel.id instead of channeland discord.utils.get()
  3. Rather than purging, delete the command msg

@client.command()
async def car(ctx):
    pictures = [
    'https://car-images.bauersecure.com/pagefiles/78294/la_auto_show_11.jpg',
    'http://www.azstreetcustom.com/uploads/2/7/8/9/2789892/az-street-custom-gt40-2_orig.jpg',
    'http://tenwheel.com/imgs/a/b/l/t/z/1967_firebird_1968_69_70_2000_camaro_blended_custom_supercharged_street_car_1_lgw.jpg',
    'https://rthirtytwotaka.files.wordpress.com/2013/06/dsc_0019.jpg',
    'http://speedhunters-wp-production.s3.amazonaws.com/wp-content/uploads/2008/06/fluke27.jpg',
    'https://i.ytimg.com/vi/pCt0KXC1tng/maxresdefault.jpg',
    'https://i2.wp.com/www.tunedinternational.com/featurecars/dorift/02.jpg',
    'http://i.imgur.com/nEbyV82.jpg',
    'https://cdn.hiconsumption.com/wp-content/uploads/2019/02/Affordable-Vintage-Japanese-Cars-0-Hero-1087x725.jpg',
    'http://speedhunters-wp-production.s3.amazonaws.com/wp-content/uploads/2012/04/IMG_0268.jpg',
    'https://i.ytimg.com/vi/Y-moGXK2zLk/maxresdefault.jpg',
    'https://www.topgear.com/sites/default/files/images/big-read/carousel/2016/03/568cd4ab437c6557c583a6f4a4feb6d1/3carguyscarouselmarch2016.jpg'
    ]
    if ctx.channel.id == 705161333972140072:
        await ctx.message.delete()
        await ctx.send(random.choice(pictures))

client.run('token')

You can also use checks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Discord py how can I join a voice channel

From Java

discord.py (rewrite) How do I make a command to a specific channel

From Dev

How can I use arial narrow in css?

From Dev

How can I use arial narrow in css?

From Dev

how can i make my discord.py bot send a message i choose to a channel i choose?

From Dev

How do I use discord.py to send a greeting message in the System Messages Channel

From Dev

How do you use permission overwrites? Discord.py Rewrite

From Dev

How do I move a user to a specific channel on discord using the discord.py API

From Dev

How to install discord.py rewrite?

From Dev

How can I replace a single space in every entry of an aray with a tab using Perl? Can I use sed-like commands?

From Dev

How can i error handle the spotify command in discord.py?

From Dev

How can I print the time of an error in discord.py?

From Dev

How can i delete role permissinos with discord.py

From Dev

discord.py - How can I have 2 arguments in a command?

From Dev

How can I execute multiple find commands in a single line?

From Dev

How can I send multiple commands' output to a single shell pipeline?

From Dev

I want to make a command that deletes a channel discord.py

From Dev

How do I restore the ability to do Terminal commands?

From Dev

How can I use channel send direction in Go

From Dev

How can I use the alpha channel un Pygame?

From Dev

How to create a category and a channel using python discord.py

From Dev

How to check if a channel has any messages? Discord.py

From Dev

discord.py How to get logs from a DM channel

From Dev

How to set number of servers that the bot is on as status (discord.py rewrite)?

From Dev

Get the channel deletor discord py

From Dev

How can I make my Discord Bot delete all messages in a channel?

From Dev

How can I make my Discord Bot delete all messages in a channel?

From Dev

How can I make the bot code independent of the channel,( I want a single bot code for facebook at work and DirectLine)

From Dev

How can I check the role of a message author + How do I DM specific roles on Discord.py?

Related Related

  1. 1

    Discord py how can I join a voice channel

  2. 2

    discord.py (rewrite) How do I make a command to a specific channel

  3. 3

    How can I use arial narrow in css?

  4. 4

    How can I use arial narrow in css?

  5. 5

    how can i make my discord.py bot send a message i choose to a channel i choose?

  6. 6

    How do I use discord.py to send a greeting message in the System Messages Channel

  7. 7

    How do you use permission overwrites? Discord.py Rewrite

  8. 8

    How do I move a user to a specific channel on discord using the discord.py API

  9. 9

    How to install discord.py rewrite?

  10. 10

    How can I replace a single space in every entry of an aray with a tab using Perl? Can I use sed-like commands?

  11. 11

    How can i error handle the spotify command in discord.py?

  12. 12

    How can I print the time of an error in discord.py?

  13. 13

    How can i delete role permissinos with discord.py

  14. 14

    discord.py - How can I have 2 arguments in a command?

  15. 15

    How can I execute multiple find commands in a single line?

  16. 16

    How can I send multiple commands' output to a single shell pipeline?

  17. 17

    I want to make a command that deletes a channel discord.py

  18. 18

    How do I restore the ability to do Terminal commands?

  19. 19

    How can I use channel send direction in Go

  20. 20

    How can I use the alpha channel un Pygame?

  21. 21

    How to create a category and a channel using python discord.py

  22. 22

    How to check if a channel has any messages? Discord.py

  23. 23

    discord.py How to get logs from a DM channel

  24. 24

    How to set number of servers that the bot is on as status (discord.py rewrite)?

  25. 25

    Get the channel deletor discord py

  26. 26

    How can I make my Discord Bot delete all messages in a channel?

  27. 27

    How can I make my Discord Bot delete all messages in a channel?

  28. 28

    How can I make the bot code independent of the channel,( I want a single bot code for facebook at work and DirectLine)

  29. 29

    How can I check the role of a message author + How do I DM specific roles on Discord.py?

HotTag

Archive