Search code examples
pythonbotsdiscorddiscord.pytweets

Discord bot - old posts with old nicknames


I've prepared a discord bot that needs to post in name of other users, so I want it to change its nickname. I thought it went ok, but after I restart a client all posts changed to last nickname and no longer be recognizable by author.

Any ideas how to solve it? Once I saw a discord bot (https://i.sstatic.net/PGQ3a.jpg) that posts tweets and changes the name depending on whom tweets it. So I guess it is possible.


Solution

  • So you could do something like this

    import discord
    import random
    import asyncio
    from discord.ext.commands import Bot
    
    client = Bot(command_prefix='!', case_insensitive=True)
    
    @client.command(pass_context=True)
    async def nick(ctx):
      await client.change_nickname(ctx.message.server.get_member("bot_id"),f"Name #{random.randrange(30)}")
      embed = discord.Embed()
      await asyncio.sleep(.01)
      embed.add_field(name = "Poster: ",value = ctx.message.server.get_member("bot_id").nick)
      await client.send_message(ctx.message.channel,embed = embed)
    

    I'm not sure if you've tried this but the way that Twitter bot does it also resets its nickname to your client whenever you restart Discord

    He also inserts the name of whoever is tweeting into the embed which lasts even after you restart the client.